Search in sources :

Example 1 with Extension

use of eu.etaxonomy.cdm.model.common.Extension in project cdmlib by cybertaxonomy.

the class IpniServiceTest method testGetAuthors.

@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testGetAuthors() {
    ICdmRepository services = null;
    IpniServiceAuthorConfigurator config = new IpniServiceAuthorConfigurator();
    config.setFormat(DelimitedFormat.EXTENDED);
    List<Person> authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
    // expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
    if (authorList == null) {
        Assert.fail("No results.");
    }
    if (testInternetConnectivity(authorList)) {
        Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
        Person author = authorList.get(0);
        // full title
        Assert.assertEquals("Full title for Greuter should be 'Werner Rodolfo Greuter'", "Werner Rodolfo Greuter", author.getFullTitle());
        // title cache
        Assert.assertEquals("Title cache for Greuter should be 'Greuter, W.R.'", "Greuter, W.R.", author.getTitleCache());
        // alternative names
        Assert.assertEquals("One extension for the alternative name should exist", 1, author.getExtensions().size());
        Extension alternativeName = author.getExtensions().iterator().next();
        Assert.assertEquals("Alternative name should be ", "Greuter, Werner Rodolfo", alternativeName.getValue());
        // dates
        String year = author.getLifespan().getYear();
        Assert.assertNotNull("Year should be not null", year);
        Assert.assertEquals("Year should be 1938", "1938", year);
        authorList = service1.getAuthors(null, "Greu*", null, null, null, config);
        // 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
        if (authorList == null) {
            Assert.fail("No results.");
        } else {
            Assert.assertEquals("There should be exactly 3 result for 'Greu*'. But maybe this changes over time", 3, authorList.size());
        }
        // for (Person person : authorList){
        // System.out.println(person.getTitleCache() + ";  " + person.getNomenclaturalTitle());
        // }
        // 
        config.setFormat(DelimitedFormat.MINIMAL);
        authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
        Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
        author = authorList.get(0);
        Assert.assertTrue("No alternative names should exist in the minimal version", author.getExtensions().isEmpty());
    }
}
Also used : Extension(eu.etaxonomy.cdm.model.common.Extension) ICdmRepository(eu.etaxonomy.cdm.api.application.ICdmRepository) Person(eu.etaxonomy.cdm.model.agent.Person) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 2 with Extension

use of eu.etaxonomy.cdm.model.common.Extension in project cdmlib by cybertaxonomy.

the class DeduplicationHelper method copyIdentifiableExtensions.

/**
 * Clones all extensions of cdmBase2 and
 * attaches the clones to cdmBase1.
 * Finally removes all annotations and markers from cdmBase2.
 * @param cdmBase1
 * @param cdmBase2
 * @param session
 */
// TODO Why do we not handle credits, rights and sources here
private <T> void copyIdentifiableExtensions(T cdmBase1, T cdmBase2, Session session) {
    IdentifiableEntity<?> identifiableEntity1 = (IdentifiableEntity<?>) cdmBase1;
    IdentifiableEntity<?> identifiableEntity2 = (IdentifiableEntity<?>) cdmBase2;
    // extensions
    List<Extension> removeListExtension = new ArrayList<>();
    for (Extension changeObject : identifiableEntity2.getExtensions()) {
        try {
            Extension clone = changeObject.clone();
            identifiableEntity1.addExtension(clone);
            removeListExtension.add(changeObject);
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException("Clone is not yet supported for class " + changeObject.getClass().getName() + " but should.");
        }
    }
    for (Extension removeObject : removeListExtension) {
        identifiableEntity2.removeExtension(removeObject);
        session.delete(removeObject);
    }
    // identifiers
    List<Identifier> removeListIdentifier = new ArrayList<>();
    for (Identifier changeObject : identifiableEntity2.getIdentifiers()) {
        try {
            Identifier clone = changeObject.clone();
            identifiableEntity1.addIdentifier(clone);
            removeListIdentifier.add(changeObject);
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }
    for (Identifier removeObject : removeListIdentifier) {
        identifiableEntity2.removeIdentifier(removeObject);
        session.delete(removeObject);
    }
}
Also used : Extension(eu.etaxonomy.cdm.model.common.Extension) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) Identifier(eu.etaxonomy.cdm.model.common.Identifier) ArrayList(java.util.ArrayList)

Example 3 with Extension

use of eu.etaxonomy.cdm.model.common.Extension in project cdmlib by cybertaxonomy.

the class CdmGenericDaoImplTest method testMergeCdmBaseReferenceAndIdentifiable.

/**
 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmGenericDaoImpl#merge(CdmBase, CdmBase)}.
 * @throws MergeException
 */
@Test
public void testMergeCdmBaseReferenceAndIdentifiable() throws MergeException {
    TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    name1.setTitleCache("BotanicalName1", true);
    TaxonName name2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    name2.setTitleCache("BotanicalName2", true);
    TaxonName zooName1 = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
    name1.setTitleCache("ZoologicalName1", true);
    Reference article1 = ReferenceFactory.newArticle();
    Reference article2 = ReferenceFactory.newArticle();
    name1.setNomenclaturalReference(article1);
    name2.setNomenclaturalReference(article2);
    Taxon taxon1 = Taxon.NewInstance(name1, article1);
    Taxon taxon2 = Taxon.NewInstance(name2, article2);
    // Person author = Person.NewInstance();
    // author.setTitleCache("Author");
    Annotation annotation1 = Annotation.NewInstance("A1", Language.DEFAULT());
    Annotation annotation2 = Annotation.NewInstance("A2", Language.DEFAULT());
    article1.addAnnotation(annotation1);
    article2.addAnnotation(annotation2);
    Marker marker1 = Marker.NewInstance(MarkerType.COMPLETE(), false);
    Marker marker2 = Marker.NewInstance(MarkerType.IMPORTED(), false);
    article1.addMarker(marker1);
    article2.addMarker(marker2);
    Rights rights1 = Rights.NewInstance();
    Rights rights2 = Rights.NewInstance();
    article1.addRights(rights1);
    article2.addRights(rights2);
    Credit credit1 = Credit.NewInstance(Team.NewInstance(), "credit1");
    Credit credit2 = Credit.NewInstance(Team.NewInstance(), "credit2");
    article1.addCredit(credit1);
    article2.addCredit(credit2);
    Extension extension1 = Extension.NewInstance();
    Extension extension2 = Extension.NewInstance();
    article1.addExtension(extension1);
    article2.addExtension(extension2);
    IdentifiableSource source1 = IdentifiableSource.NewInstance(OriginalSourceType.Unknown);
    IdentifiableSource source2 = IdentifiableSource.NewInstance(OriginalSourceType.Unknown);
    article1.addSource(source1);
    article2.addSource(source2);
    Media media1 = Media.NewInstance();
    Media media2 = Media.NewInstance();
    article1.addMedia(media1);
    article2.addMedia(media2);
    // ref1.setAuthorship(author);
    // name1.setBasionymAuthorship(author);
    name1.setNomenclaturalReference(article1);
    nameDao.save(name1);
    nameDao.save(name2);
    nameDao.save(zooName1);
    TaxonDescription taxDesc = TaxonDescription.NewInstance(taxon1);
    taxDesc.setTitleCache("taxDesc", true);
    taxDesc.addSource(OriginalSourceType.Unknown, null, null, article2, null);
    taxonDao.save(taxon1);
    // unidircetional reference to the merged object should be redirected
    cdmGenericDao.merge(article1, article2, null);
    Assert.assertEquals("Name2 must have article 1 as new nomRef", article1, name2.getNomenclaturalReference());
    // TODO microCitations!! -> warning
    // Annotations
    Assert.assertEquals("Annotation number should be 2 (1 from each of the merged objects)", 2, article1.getAnnotations().size());
    // Marker
    Assert.assertEquals("Marker number should be 2 (1 from each of the merged objects)", 2, article1.getMarkers().size());
    // Rights
    Assert.assertEquals("Rights number should be 2 (1 from each of the merged objects)", 2, article1.getRights().size());
    // Credits
    Assert.assertEquals("Credits number should be 2 (1 from each of the merged objects)", 2, article1.getCredits().size());
    // Extensions
    Assert.assertEquals("Extensions number should be 2 (1 from each of the merged objects)", 2, article1.getExtensions().size());
    // Sources
    Assert.assertEquals("Sources number should be 2 (1 from each of the merged objects)", 2, article1.getSources().size());
    // Media
    Assert.assertEquals("Media number should be 2 (1 from each of the merged objects)", 2, article1.getMedia().size());
    // Description sources
    Assert.assertEquals("Number of sources for taxon description must be 1", 1, taxDesc.getSources().size());
    Assert.assertEquals("Taxon description must have article1 as source", taxDesc.getSources().iterator().next().getCitation(), article1);
    // test exceptions
    testMergeExceptions(name1, name2, taxon1, zooName1);
// FIXME TO BE IMPLEMENTED
// current defalt implementation for rights, credits and media is ADD_CLONE and therefore the below tests don't work
// TODO is this the wanted default behaviour?
// Assert.assertTrue("Rights2 must be contained in the rights", article1.getRights().contains(rights2));
// Assert.assertTrue("Credits2 must be contained in the credits", article1.getCredits().contains(credit2));
// Assert.assertTrue("Media2 must be contained in the media", article1.getMedia().contains(media2));
}
Also used : Extension(eu.etaxonomy.cdm.model.common.Extension) Rights(eu.etaxonomy.cdm.model.media.Rights) Credit(eu.etaxonomy.cdm.model.common.Credit) Reference(eu.etaxonomy.cdm.model.reference.Reference) IntextReference(eu.etaxonomy.cdm.model.common.IntextReference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Media(eu.etaxonomy.cdm.model.media.Media) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Marker(eu.etaxonomy.cdm.model.common.Marker) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) Annotation(eu.etaxonomy.cdm.model.common.Annotation) Test(org.junit.Test) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)

Example 4 with Extension

use of eu.etaxonomy.cdm.model.common.Extension in project cdmlib by cybertaxonomy.

the class SpecimenTest method testClone.

@Test
public void testClone() {
    logger.debug("Start testClone");
    // Null test is not full implemented, but an error is thrown if null throws
    // null pointer exception somewhere
    DerivedUnit specimenNullClone = specimen.clone();
    String accessionNumber = "accNumber";
    String catalogNumber = "catNumber";
    Collection collection = Collection.NewInstance();
    collection.setCode("code");
    DateTime created = new DateTime();
    Person createdBy = Person.NewTitledInstance("creator");
    DerivationEvent derivedFrom = DerivationEvent.NewInstance(null);
    int id = 22;
    String individualCount = "25";
    DefinedTerm lifeStage = DefinedTerm.NewStageInstance(null, null, null);
    LSID lsid = null;
    try {
        lsid = new LSID("urn:lsid:example.com:foo:1");
    } catch (MalformedLSIDException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // DerivedUnit nextVersion = DerivedUnit.NewPreservedSpecimenInstance();
    // DerivedUnit previousVersion = DerivedUnit.NewPreservedSpecimenInstance();
    PreservationMethod preservation = PreservationMethod.NewInstance();
    boolean protectedTitleCache = true;
    DefinedTerm sex = DefinedTerm.SEX_FEMALE();
    TaxonName storedUnder = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
    String titleCache = "title";
    Calendar updated = Calendar.getInstance();
    Person updatedBy = Person.NewTitledInstance("updatedPerson");
    UUID uuid = UUID.randomUUID();
    Annotation annotation = Annotation.NewDefaultLanguageInstance("annotation");
    String definition = "definition";
    // TODO
    DerivationEvent derivationEvent = DerivationEvent.NewInstance(null);
    SpecimenDescription description = SpecimenDescription.NewInstance();
    DeterminationEvent determination = DeterminationEvent.NewInstance();
    Extension extension = Extension.NewInstance();
    extension.setValue("extension");
    Marker marker = Marker.NewInstance(MarkerType.COMPLETE(), false);
    Rights right = Rights.NewInstance("right", Language.DEFAULT());
    // Media media = Media.NewInstance();
    IdentifiableSource source = IdentifiableSource.NewDataImportInstance("12", "idNamespace");
    specimen.setAccessionNumber(accessionNumber);
    specimen.setCatalogNumber(catalogNumber);
    specimen.setCollection(collection);
    specimen.setCreated(created);
    // specimen.setCreatedBy(createdBy);
    specimen.setDerivedFrom(derivedFrom);
    specimen.setId(id);
    specimen.setIndividualCount(individualCount);
    specimen.setLifeStage(lifeStage);
    specimen.setLsid(lsid);
    specimen.setPreservation(preservation);
    specimen.setProtectedTitleCache(protectedTitleCache);
    specimen.setSex(sex);
    specimen.setStoredUnder(storedUnder);
    specimen.setTitleCache(titleCache, protectedTitleCache);
    // specimen.setUpdated(updated);
    // specimen.setUpdatedBy(updatedBy);
    specimen.setUuid(uuid);
    specimen.addAnnotation(annotation);
    specimen.putDefinition(Language.DEFAULT(), definition);
    specimen.addDerivationEvent(derivationEvent);
    specimen.addDescription(description);
    specimen.addDetermination(determination);
    specimen.addExtension(extension);
    specimen.addMarker(marker);
    // specimen.addMedia(media);    #3597
    specimen.addRights(right);
    specimen.addSource(source);
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {
    // ignore
    }
    DerivedUnit specimenClone = specimen.clone();
    assertFalse(id == specimenClone.getId());
    assertFalse(created.equals(specimenClone.getCreated()));
    assertFalse(createdBy.equals(specimenClone.getCreatedBy()));
    assertFalse(updated.equals(specimenClone.getUpdated()));
    assertFalse(updatedBy.equals(specimenClone.getUpdatedBy()));
    assertNull(specimenClone.getUpdatedBy());
    assertNull(specimenClone.getCreatedBy());
    assertFalse(uuid.equals(specimenClone.getUuid()));
    assertEquals(accessionNumber, specimenClone.getAccessionNumber());
    assertEquals(catalogNumber, specimenClone.getCatalogNumber());
    assertEquals(collection, specimenClone.getCollection());
    assertEquals(derivedFrom, specimenClone.getDerivedFrom());
    assertEquals(lifeStage, specimenClone.getLifeStage());
    assertEquals(lsid, specimenClone.getLsid());
    assertEquals(preservation, specimenClone.getPreservation());
    assertEquals(protectedTitleCache, specimenClone.isProtectedTitleCache());
    assertEquals(storedUnder, specimenClone.getStoredUnder());
    assertEquals(sex, specimenClone.getSex());
    assertEquals(titleCache, specimenClone.getTitleCache());
    Annotation clonedAnnotation = specimenClone.getAnnotations().iterator().next();
    assertFalse(annotation.equals(clonedAnnotation));
    assertEquals(annotation.getText(), ((LanguageStringBase) specimenClone.getAnnotations().iterator().next()).getText());
    assertNotSame(annotation, specimenClone.getAnnotations().iterator().next());
    assertEquals(definition, specimenClone.getDefinition().get(Language.DEFAULT()).getText());
    // TODO
    // assertNotSame(definition, specimenClone.getDefinition().getText(Language.DEFAULT()));
    assertEquals(derivationEvent, specimenClone.getDerivationEvents().iterator().next());
    assertSame(derivationEvent, specimenClone.getDerivationEvents().iterator().next());
    // FIXME check if descriptions and determinations were correctly cloned
    // assertEquals(description, specimenClone.getDescriptions().iterator().next());
    // // TODO ?
    // assertSame(description, specimenClone.getDescriptions().iterator().next());
    // 
    // assertEquals(determination, specimenClone.getDeterminations().iterator().next());
    // // TODO ?
    // assertSame(determination, specimenClone.getDeterminations().iterator().next());
    assertFalse(extension.equals(specimenClone.getExtensions().iterator().next()));
    assertEquals(extension.getValue(), specimenClone.getExtensions().iterator().next().getValue());
    assertNotSame(extension, specimenClone.getExtensions().iterator().next());
    assertEquals(1, specimen.getExtensions().size());
    assertFalse(marker.equals(specimenClone.getMarkers().iterator().next()));
    assertEquals(marker.getFlag(), specimenClone.getMarkers().iterator().next().getFlag());
    assertNotSame(marker, specimenClone.getMarkers().iterator().next());
    assertEquals(1, specimenClone.getMarkers().size());
    // assertEquals(media, specimenClone.getMedia().iterator().next());  #3597
    // assertEquals(right, specimenClone.getRights().iterator().next()); #5762
    assertTrue("Rights must contain 1 rights object", specimenClone.getRights().size() == 1);
    assertTrue("Rights must not be cloned", specimenClone.getRights().iterator().next().equals(right));
    assertFalse(source.equals(specimenClone.getSources().iterator().next()));
    assertEquals(source.getId(), ((OriginalSourceBase) specimenClone.getSources().iterator().next()).getId());
    assertNotSame(source, specimenClone.getSources().iterator().next());
    assertEquals(1, specimenClone.getSources().size());
}
Also used : LSID(eu.etaxonomy.cdm.model.common.LSID) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) Calendar(java.util.Calendar) Marker(eu.etaxonomy.cdm.model.common.Marker) DateTime(org.joda.time.DateTime) Annotation(eu.etaxonomy.cdm.model.common.Annotation) Extension(eu.etaxonomy.cdm.model.common.Extension) Rights(eu.etaxonomy.cdm.model.media.Rights) MalformedLSIDException(com.ibm.lsid.MalformedLSIDException) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) UUID(java.util.UUID) Person(eu.etaxonomy.cdm.model.agent.Person) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm) Test(org.junit.Test)

Example 5 with Extension

use of eu.etaxonomy.cdm.model.common.Extension in project cdmlib by cybertaxonomy.

the class DbImportExtensionCreationMapper method createObject.

/* (non-Javadoc)
	 * @see eu.etaxonomy.cdm.io.common.mapping.DbImportObjectCreationMapperBase#createObject(java.sql.ResultSet)
	 */
@Override
protected Extension createObject(ResultSet rs) throws SQLException {
    Extension extension = Extension.NewInstance();
    extension.setType(this.supplementType);
    return extension;
}
Also used : Extension(eu.etaxonomy.cdm.model.common.Extension)

Aggregations

Extension (eu.etaxonomy.cdm.model.common.Extension)9 Annotation (eu.etaxonomy.cdm.model.common.Annotation)3 ExtensionType (eu.etaxonomy.cdm.model.common.ExtensionType)3 UUID (java.util.UUID)3 Test (org.junit.Test)3 Person (eu.etaxonomy.cdm.model.agent.Person)2 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)2 Marker (eu.etaxonomy.cdm.model.common.Marker)2 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)2 Rights (eu.etaxonomy.cdm.model.media.Rights)2 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)2 Reference (eu.etaxonomy.cdm.model.reference.Reference)2 ArrayList (java.util.ArrayList)2 MalformedLSIDException (com.ibm.lsid.MalformedLSIDException)1 ICdmRepository (eu.etaxonomy.cdm.api.application.ICdmRepository)1 PostfixTerm (eu.etaxonomy.cdm.io.excel.common.ExcelRowBase.PostfixTerm)1 SourceDataHolder (eu.etaxonomy.cdm.io.excel.common.ExcelRowBase.SourceDataHolder)1 AnnotationType (eu.etaxonomy.cdm.model.common.AnnotationType)1 Credit (eu.etaxonomy.cdm.model.common.Credit)1 IdentifiableEntity (eu.etaxonomy.cdm.model.common.IdentifiableEntity)1