From aec873776082711e6dce5c84c26384ebdb03f154 Mon Sep 17 00:00:00 2001 From: Patric Plitzner Date: Tue, 21 Oct 2014 10:48:38 +0000 Subject: [PATCH] - adapted to cdm3.4 changes --- .../FullCoverageDataGenerator.java | 272 +++++++++--------- 1 file changed, 136 insertions(+), 136 deletions(-) diff --git a/cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/datagenerator/FullCoverageDataGenerator.java b/cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/datagenerator/FullCoverageDataGenerator.java index 4d2769beba..9393dddb05 100644 --- a/cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/datagenerator/FullCoverageDataGenerator.java +++ b/cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/datagenerator/FullCoverageDataGenerator.java @@ -1,5 +1,5 @@ /** - * + * */ package eu.etaxonomy.cdm.datagenerator; @@ -116,43 +116,43 @@ import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser; /** - * This class tries to create a database that has + * This class tries to create a database that has * at least one record in each database. * It is meant to test update scripts as well as imports * and exports. - * ATTENTION: As the content of the created database may change + * ATTENTION: As the content of the created database may change * over time due to model changes and other requirements test using - * this class should be written in a way that they do rather - * depend on general parameter than concrete data values. - * + * this class should be written in a way that they do rather + * depend on general parameter than concrete data values. + * * @author a.mueller * @created 3013-12-02 - * + * * TODO under construction - * + * */ public class FullCoverageDataGenerator { - + public void fillWithData(Session session){ - List cdmBases = new ArrayList(); - + List cdmBases = new ArrayList(); + createAgents(cdmBases); - + createDescriptions(cdmBases); - + createMedia(cdmBases); - + createMolecular(cdmBases); - + createTaxonName(cdmBases); - + createOccurrence(cdmBases); - + createReference(cdmBases); - + createTaxon(cdmBases); - + for (CdmBase cdmBase: cdmBases){ session.save(cdmBase); } @@ -170,9 +170,9 @@ public class FullCoverageDataGenerator { person.setLifespan(TimePeriodParser.parseString("1905-1995")); person.setPrefix("prefix"); person.setSuffix("suffix"); - + handleIdentifiableEntity(person); - + //Contact Contact contact = Contact.NewInstance(); person.setContact(contact); @@ -180,45 +180,45 @@ public class FullCoverageDataGenerator { contact.addEmailAddress("a@b.de"); contact.addFaxNumber("f:010-123456"); contact.addPhoneNumber("p:090-987654"); - contact.addUrl(URI.create("http://www.abc.de").toString()); - + contact.addUrl(URI.create("http://www.abc.de")); + //Address Address address = Address.NewInstance(Country.GERMANY(), "locality", "pobox", "12345", "region", "street", locality); contact.addAddress(address); - + //Team Team team = Team.NewTitledInstance("Team title", "Team abbrev title"); team.addTeamMember(person); handleIdentifiableEntity(team); - - + + //Institution Institution institution = Institution.NewInstance(); institution.setCode("institution code"); institution.setName("institution name"); handleIdentifiableEntity(institution); - - + + //TODO vocabulary // voc = "29ad808b-3126-4274-be81-4561e7afc76f" DefinedTerm instType = DefinedTerm.NewInstitutionTypeInstance("Description forthis instition type", "institution type", "inst. t."); cdmBases.add(instType); institution.addType(instType); person.addInstitutionalMembership(institution, TimePeriodParser.parseString("1955-1956"), "department", "role"); - + Institution subInstitution = Institution.NewInstance(); subInstitution.setCode("sub institution code"); subInstitution.setName("sub institution name"); subInstitution.setIsPartOf(institution); - + cdmBases.add(person); cdmBases.add(team); cdmBases.add(institution); } - + private void createDescriptions(List cdmBases) { - + //Categorical data State state = State.NewInstance("Test state", "state", "st."); cdmBases.add(state); @@ -226,15 +226,15 @@ public class FullCoverageDataGenerator { StateData stateData = categoricalData.getStateData().get(0); stateData.addModifier(DefinedTerm.SEX_FEMALE()); handleAnnotatableEntity(categoricalData); - - + + State nextState = State.NewInstance(); cdmBases.add(nextState); StateData stateData2 = StateData.NewInstance(nextState); stateData2.putModifyingText(Language.ENGLISH(), "State2 modifying text"); categoricalData.addStateData(stateData2); categoricalData.setOrderRelevant(true); - + //Quantitative data Feature leaveLength = Feature.NewInstance("Leave length description", "leave length", "l.l."); cdmBases.add(leaveLength); @@ -246,47 +246,47 @@ public class FullCoverageDataGenerator { quantitativeData.setAverage((float)22.9 , null); handleAnnotatableEntity(quantitativeData); handleIdentifiableEntity(measurementUnit); - - + + CommonTaxonName commonTaxonName = CommonTaxonName.NewInstance("common name", Language.ENGLISH(), Country.UNITEDSTATESOFAMERICA()); handleAnnotatableEntity(commonTaxonName); - + TextData textData = TextData.NewInstance(Feature.DIAGNOSIS()); textData.putModifyingText(Language.ENGLISH(), "nice diagnosis"); handleAnnotatableEntity(textData); - + TextFormat format = TextFormat.NewInstance("format", "format", null); textData.setFormat(format); cdmBases.add(format); handleAnnotatableEntity(format); - + DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen); IndividualsAssociation indAssoc = IndividualsAssociation.NewInstance(specimen); indAssoc.putDescription(Language.ENGLISH(), "description for individuals association"); handleAnnotatableEntity(indAssoc); - - + + TaxonInteraction taxonInteraction = TaxonInteraction.NewInstance(Feature.HOSTPLANT()); taxonInteraction.putDescription(Language.ENGLISH(), "interaction description"); handleAnnotatableEntity(taxonInteraction); - + Distribution distribution = Distribution.NewInstance(Country.GERMANY(), PresenceTerm.CULTIVATED()); handleAnnotatableEntity(distribution); - - + + Taxon taxon = getTaxon(); TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon); - taxonDescription.addElements(categoricalData, quantitativeData, + taxonDescription.addElements(categoricalData, quantitativeData, textData, commonTaxonName, taxonInteraction, indAssoc, distribution); - - DerivedUnit describedSpecimenOrObservation = DerivedUnit.NewInstance(SpecimenOrObservationType.DerivedUnit); + + DerivedUnit describedSpecimenOrObservation = DerivedUnit.NewInstance(SpecimenOrObservationType.DerivedUnit); taxonDescription.setDescribedSpecimenOrObservation(describedSpecimenOrObservation); - + taxonDescription.addScope(DefinedTerm.SEX_FEMALE()); taxonDescription.addGeoScope(Country.GERMANY()); handleIdentifiableEntity(taxonDescription); - - + + cdmBases.add(taxon); //DescriptionElmenetBase + source @@ -298,29 +298,29 @@ public class FullCoverageDataGenerator { DescriptionElementSource source = textData.addSource(OriginalSourceType.Import, "22", "taxon description table", ref, "detail"); source.setNameUsedInSource(BotanicalName.NewInstance(Rank.GENUS())); handleAnnotatableEntity(source); - - + + //Specimen description SpecimenOrObservationBase describedSpecimen = getSpecimen(); SpecimenDescription specDesc = SpecimenDescription.NewInstance(specimen); cdmBases.add(describedSpecimen); handleAnnotatableEntity(specDesc); - + //Name description TaxonNameBase name = BotanicalName.NewInstance(Rank.GENUS()); TaxonNameDescription nameDesc = TaxonNameDescription.NewInstance(name); cdmBases.add(name); handleAnnotatableEntity(nameDesc); - - + + //Feature Tree FeatureTree featureTree = FeatureTree.NewInstance(); FeatureNode descriptionFeatureNode = FeatureNode.NewInstance(Feature.DESCRIPTION()); FeatureNode leaveLengthNode = FeatureNode.NewInstance(leaveLength); featureTree.getRootChildren().add(descriptionFeatureNode); descriptionFeatureNode.addChild(leaveLengthNode); - handleIdentifiableEntity(featureTree); - + handleIdentifiableEntity(featureTree); + State inapplicableState = State.NewInstance("inapplicableState", "inapplicableState", null); State applicableState = State.NewInstance("only applicable state", "only applicable state", null); cdmBases.add(applicableState); @@ -328,49 +328,49 @@ public class FullCoverageDataGenerator { leaveLengthNode.addInapplicableState(inapplicableState); leaveLengthNode.addApplicableState(applicableState); cdmBases.add(featureTree); - - + + WorkingSet workingSet = WorkingSet.NewInstance(); workingSet.addDescription(taxonDescription); workingSet.setLabel("My Workingset"); workingSet.getDescriptiveSystem(); handleAnnotatableEntity(workingSet); - - + + //polytomous keys Taxon coveredTaxon = Taxon.NewInstance(name, null); PolytomousKey key = PolytomousKey.NewTitledInstance("My Polykey"); handleIdentificationKey(key, taxon, coveredTaxon); key.setStartNumber(10); - - + + PolytomousKeyNode firstChildNode = PolytomousKeyNode.NewInstance("Green", "What is the leave length?", coveredTaxon, leaveLength); key.getRoot().addChild(firstChildNode); PolytomousKeyNode secondChildNode = PolytomousKeyNode.NewInstance("234"); firstChildNode.addChild(secondChildNode); - + PolytomousKey subkey = PolytomousKey.NewTitledInstance("Sub-key"); firstChildNode.setSubkey(subkey); - + PolytomousKeyNode subKeyNode = PolytomousKeyNode.NewInstance("sub key couplet"); subkey.getRoot().addChild(subKeyNode); secondChildNode.setOtherNode(subKeyNode); - + secondChildNode.putModifyingText(Language.GERMAN(), "manchmal"); - + cdmBases.add(key); cdmBases.add(subkey); - + MediaKey mediaKey = MediaKey.NewInstance(); mediaKey.addKeyRepresentation(Representation.NewInstance("Media Key Representation", "media key", null, Language.ENGLISH())); handleIdentificationKey(mediaKey, taxon, coveredTaxon); - + MultiAccessKey multiAccessKey = MultiAccessKey.NewInstance(); handleIdentificationKey(multiAccessKey, taxon, coveredTaxon); - + cdmBases.add(mediaKey); cdmBases.add(multiAccessKey); - + } @@ -385,39 +385,39 @@ public class FullCoverageDataGenerator { }else{ handleAnnotatableEntity((AnnotatableEntity)key); } - + } - - + + private void createMedia(List cdmBases){ AudioFile audioFile = AudioFile.NewInstance(URI.create("http://a.b.de"), 22); ImageFile imageFile = ImageFile.NewInstance(URI.create("http://b.c.de"), 44, 467, 55); MovieFile movieFile = MovieFile.NewInstance(URI.create("http://b.c.de"), 67); - MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance("mime", "media"); - + MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance("mime", "media"); + mediaRepresentation.addRepresentationPart(movieFile); mediaRepresentation.addRepresentationPart(imageFile); mediaRepresentation.addRepresentationPart(audioFile); Media media = Media.NewInstance(); media.addRepresentation(mediaRepresentation); - + media.putTitle(Language.ENGLISH(), "Media title"); media.setMediaCreated(DateTime.now()); media.putDescription(Language.ENGLISH(), "Media description"); handleIdentifiableEntity(media); - - + + Person artist = Person.NewTitledInstance("artist"); media.setArtist(artist); cdmBases.add(media); cdmBases.add(artist); } - + private void createMolecular(List cdmBases) { DnaSample dnaSample = DnaSample.NewInstance(); - + //Amplification Amplification amplification = Amplification.NewInstance(dnaSample); DefinedTerm dnaMarker = DefinedTerm.NewDnaMarkerInstance("My dna marker", "dna marker", null); @@ -426,40 +426,40 @@ public class FullCoverageDataGenerator { amplification.setSuccessful(true); amplification.setSuccessText("Very successful"); handleAnnotatableEntity(amplification); - + Primer forwardPrimer = Primer.NewInstance("forward primer"); forwardPrimer.setPublishedIn(getReference()); - forwardPrimer.setSequence(Sequence.NewInstance("my sequence")); + forwardPrimer.setSequence(SequenceString.NewInstance("my sequence")); handleAnnotatableEntity(forwardPrimer); - + Primer reversePrimer = Primer.NewInstance("reverse primer"); handleAnnotatableEntity(reversePrimer); - + amplification.setForwardPrimer(forwardPrimer); amplification.setReversePrimer(reversePrimer); - + DefinedTerm cloningMethod = DefinedTerm.NewInstance(TermType.MaterialOrMethod, "cloning method", "cloning method", null); cdmBases.add(cloningMethod); Cloning cloning = Cloning.NewInstance(cloningMethod, "My cloning method", "my strain", forwardPrimer, reversePrimer); amplification.setCloning(cloning); handleAnnotatableEntity(cloningMethod); handleAnnotatableEntity(cloning); - + DefinedTerm purificationMethod = DefinedTerm.NewInstance(TermType.MaterialOrMethod, "purification method", "purification method", null); cdmBases.add(purificationMethod); MaterialOrMethodEvent purification = MaterialOrMethodEvent.NewInstance(purificationMethod, "purification method"); amplification.setPurification(purification); handleAnnotatableEntity(purification); handleAnnotatableEntity(purificationMethod); - + amplification.setLadderUsed("ladder"); amplification.setElectrophoresisVoltage(5.5); amplification.setGelConcentration(2.4); amplification.setGelRunningTime(3.6); Media gelPhoto = Media.NewInstance(); amplification.setGelPhoto(gelPhoto); - - + + //SingleRead SingleRead singleRead = SingleRead.NewInstance(); handleAnnotatableEntity(singleRead); @@ -467,14 +467,14 @@ public class FullCoverageDataGenerator { MaterialOrMethodEvent readMethod = MaterialOrMethodEvent.NewInstance(null, "read method"); singleRead.setMaterialOrMethod(readMethod); handleAnnotatableEntity(readMethod); - + Media pherogram = Media.NewInstance(); singleRead.setPherogram(pherogram); - + singleRead.setPrimer(forwardPrimer); singleRead.setSequence(SequenceString.NewInstance("ABTC")); singleRead.setDirection(SequenceDirection.Forward); - + //Seuqence Sequence sequence = Sequence.NewInstance("ADDT"); dnaSample.addSequence(sequence); @@ -490,13 +490,13 @@ public class FullCoverageDataGenerator { Reference sequenceCitation = getReference(); sequence.addCitation(sequenceCitation); handleAnnotatableEntity(sequence); - + //Phylogenetic Tree PhylogeneticTree phyloTree = PhylogeneticTree.NewInstance(); phyloTree.addUsedSequences(sequence); handleIdentifiableEntity(phyloTree); - - + + cdmBases.add(dnaSample); cdmBases.add(phyloTree); } @@ -510,21 +510,21 @@ public class FullCoverageDataGenerator { TaxonNameBase synName = BotanicalName.NewInstance(Rank.GENUS()); Synonym syn = Synonym.NewInstance(synName, sec); - taxon.addSynonym(syn, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), + taxon.addSynonym(syn, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), getReference(), "123"); taxon.setDoubtful(true); handleIdentifiableEntity(syn); - + Taxon concept = Taxon.NewInstance(name, getReference()); - TaxonRelationship taxRel = taxon.addTaxonRelation(concept, TaxonRelationshipType.CONGRUENT_TO(), + TaxonRelationship taxRel = taxon.addTaxonRelation(concept, TaxonRelationshipType.CONGRUENT_TO(), sec, "444"); taxon.setTaxonStatusUnknown(true); taxon.setUnplaced(true); taxon.setExcluded(true); handleAnnotatableEntity(taxRel); - + //Classification Classification classification = Classification.NewInstance("My classification", sec); TaxonNode node = classification.addChildTaxon(taxon, sec,"22"); @@ -532,13 +532,13 @@ public class FullCoverageDataGenerator { Taxon childTaxon = Taxon.NewInstance(synName, sec); node.addChildTaxon(childTaxon, sec, "44"); - + cdmBases.add(taxon); cdmBases.add(concept); cdmBases.add(childTaxon); cdmBases.add(classification); - - + + } @@ -547,7 +547,7 @@ public class FullCoverageDataGenerator { private void createReference(List cdmBases) { Reference reference = ReferenceFactory.newArticle(); Person author = Person.NewTitledInstance("Author team"); - reference.setAuthorTeam(author); + reference.setAuthorship(author); reference.setTitle("ref title"); reference.setAbbrevTitle("abbrev title"); reference.setDatePublished(TimePeriodParser.parseString("1999")); @@ -569,14 +569,14 @@ public class FullCoverageDataGenerator { reference.setSeriesPart("seriesPart"); reference.setVolume("vol. 3"); reference.setUri(URI.create("http://rer.abc.de")); - + Reference journal = ReferenceFactory.newJournal(); reference.setInJournal(journal); - + handleIdentifiableEntity(reference); cdmBases.add(reference); - + } @@ -589,15 +589,15 @@ public class FullCoverageDataGenerator { subCollection.setSuperCollection(collection); handleIdentifiableEntity(collection); handleIdentifiableEntity(subCollection); - - + + collection.setCode("coll code"); collection.setCodeStandard("codeStandard"); collection.setName("coll name"); collection.setTownOrLocation("townOrLocation"); Institution institution = Institution.NewInstance(); collection.setInstitute(institution); - + //FieldUnit FieldUnit fieldUnit = FieldUnit.NewInstance(); fieldUnit.setFieldNumber("fieldNumber"); @@ -609,7 +609,7 @@ public class FullCoverageDataGenerator { GatheringEvent gatheringEvent = GatheringEvent.NewInstance(); fieldUnit.setGatheringEvent(gatheringEvent); gatheringEvent.putLocality(Language.ENGLISH(), "locality"); - gatheringEvent.setExactLocation(Point.NewInstance(22.4, -34.2, + gatheringEvent.setExactLocation(Point.NewInstance(22.4, -34.2, ReferenceSystem.WGS84(), 33)); gatheringEvent.setCountry(Country.GERMANY()); gatheringEvent.addCollectingArea(NamedArea.EUROPE()); @@ -617,7 +617,7 @@ public class FullCoverageDataGenerator { gatheringEvent.setAbsoluteElevation(10); gatheringEvent.setAbsoluteElevationMax(100); gatheringEvent.setAbsoluteElevationText("elevation text"); - + gatheringEvent.setDistanceToGround(10.4); gatheringEvent.setDistanceToGroundMax(100.3); gatheringEvent.setDistanceToGroundText("distance to ground text"); @@ -627,7 +627,7 @@ public class FullCoverageDataGenerator { gatheringEvent.setDistanceToWaterSurfaceText("distance to water text"); handleAnnotatableEntity(gatheringEvent); - + //Derived Unit MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.StillImage); mediaSpecimen.setCollection(collection); @@ -650,7 +650,7 @@ public class FullCoverageDataGenerator { event.addDerivative(mediaSpecimen); handleAnnotatableEntity(event); - + //SpecOrObservationBase fieldUnit.setSex(DefinedTerm.SEX_FEMALE()); DefinedTerm lifeStage = DefinedTerm.NewStageInstance("Live stage", "stage", null); @@ -682,7 +682,7 @@ public class FullCoverageDataGenerator { bacName.setSubGenusAuthorship("sub Genus author"); bacName.setNameApprobation("nameApprobation"); handleIdentifiableEntity(bacName); - + CultivarPlantName botName = CultivarPlantName.NewInstance(Rank.SUBSPECIES()); botName.setAnamorphic(true); botName.setCultivarName("cultivarName"); @@ -700,7 +700,7 @@ public class FullCoverageDataGenerator { botName.setExBasionymAuthorTeam(exBasionymAuthorTeam); handleIdentifiableEntity(botName); - + ZoologicalName zooName = ZoologicalName.NewInstance(Rank.GENUS()); zooName.setBreed("breed"); zooName.setPublicationYear(1922); @@ -715,40 +715,40 @@ public class FullCoverageDataGenerator { //TypeDesignation ZoologicalName speciesZooName = ZoologicalName.NewInstance(Rank.SPECIES()); - zooName.addNameTypeDesignation(speciesZooName, getReference(), "111", "original name", + zooName.addNameTypeDesignation(speciesZooName, getReference(), "111", "original name", NameTypeDesignationStatus.AUTOMATIC(), true, true, true, true); - speciesZooName.addSpecimenTypeDesignation(getSpecimen(), SpecimenTypeDesignationStatus.HOLOTYPE(), + speciesZooName.addSpecimenTypeDesignation(getSpecimen(), SpecimenTypeDesignationStatus.HOLOTYPE(), getReference(), "p,22", "original name", false, true); - + ViralName viralName = ViralName.NewInstance(Rank.GENUS()); viralName.setAcronym("acronym"); handleIdentifiableEntity(viralName); - + cdmBases.add(bacName); cdmBases.add(botName); cdmBases.add(viralName); cdmBases.add(zooName); } - + private void handleAnnotatableEntity(AnnotatableEntity entity){ Annotation annotation = Annotation.NewDefaultLanguageInstance("annotation"); entity.addAnnotation(annotation); Marker marker = Marker.NewInstance(MarkerType.COMPLETE(), true); entity.addMarker(marker); } - + private void handleIdentifiableEntity(IdentifiableEntity identifiableEntity){ handleAnnotatableEntity(identifiableEntity); - + //Credits Person creditor = Person.NewTitledInstance("Creditor"); Credit credit = Credit.NewInstance(creditor, "credit"); identifiableEntity.addCredit(credit); - + //Extension Extension.NewInstance(identifiableEntity, "extension", ExtensionType.INFORMAL_CATEGORY()); - + //Rights Rights rights = Rights.NewInstance("right", Language.ENGLISH()); rights.setUri(URI.create("http://rights.abc.de")); @@ -757,17 +757,17 @@ public class FullCoverageDataGenerator { Person owner = Person.NewTitledInstance("Owner"); rights.setAgent(owner); identifiableEntity.addRights(rights); - + if (identifiableEntity.isInstanceOf(IdentifiableMediaEntity.class)){ Media media = Media.NewInstance(URI.create("http://www.identifiableMedia.de"), 22, "img/jpg", "jpg"); ((IdentifiableMediaEntity)identifiableEntity).addMedia(media); } - + //source - IdentifiableSource source = identifiableEntity.addSource(OriginalSourceType.Import, "id", "idNamespace", + IdentifiableSource source = identifiableEntity.addSource(OriginalSourceType.Import, "id", "idNamespace", getReference(), "123"); source.setOriginalNameString("original name"); - + //LSID try { LSID lsid = new LSID("urn:lsid:a.b.de:namespace:1234"); @@ -775,8 +775,8 @@ public class FullCoverageDataGenerator { } catch (MalformedLSIDException e) { e.printStackTrace(); } - - + + } @@ -785,13 +785,13 @@ public class FullCoverageDataGenerator { result.setTitle("some generic reference"); return result; } - - + + private DerivedUnit getSpecimen() { DerivedUnit derivedUnit = DerivedUnit.NewPreservedSpecimenInstance(); return derivedUnit; } - + private Taxon getTaxon() { @@ -799,6 +799,6 @@ public class FullCoverageDataGenerator { TaxonNameBase name = BotanicalName.NewInstance(Rank.GENUS()); Taxon taxon = Taxon.NewInstance(name, sec); return taxon; - + } } -- 2.34.1