Search in sources :

Example 1 with Credit

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

the class FullCoverageDataGenerator method handleIdentifiableEntity.

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());
    // Identifier
    Identifier identifier = identifiableEntity.addIdentifier("ident23", DefinedTerm.SEX_FEMALE());
    handleAnnotatableEntity(identifier);
    // Links
    identifiableEntity.addLinkWebsite(URI.create("http://a.bc.de"), "Description", Language.ENGLISH());
    // Rights
    Rights rights = Rights.NewInstance("right", Language.ENGLISH());
    rights.setUri(URI.create("http://rights.abc.de"));
    rights.setAbbreviatedText("abbrev");
    rights.setType(RightsType.COPYRIGHT());
    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", getReference(), "123");
    source.setOriginalNameString("original name");
    // LSID
    try {
        LSID lsid = new LSID("urn:lsid:a.b.de:namespace:1234");
        identifiableEntity.setLsid(lsid);
    } catch (MalformedLSIDException e) {
        e.printStackTrace();
    }
}
Also used : IdentifiableMediaEntity(eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity) LSID(eu.etaxonomy.cdm.model.common.LSID) Rights(eu.etaxonomy.cdm.model.media.Rights) Credit(eu.etaxonomy.cdm.model.common.Credit) Identifier(eu.etaxonomy.cdm.model.common.Identifier) MalformedLSIDException(com.ibm.lsid.MalformedLSIDException) Media(eu.etaxonomy.cdm.model.media.Media) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 2 with Credit

use of eu.etaxonomy.cdm.model.common.Credit 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 3 with Credit

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

the class CdmGenericDaoImplTest method testReallocatePersonTeam.

@Test
public void testReallocatePersonTeam() throws MergeException {
    TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
    name1.setTitleCache("BotanicalName1", true);
    IBook book1 = ReferenceFactory.newBook();
    Team team1 = Team.NewInstance();
    Team team2 = Team.NewInstance();
    team1.setTitleCache("team1", true);
    team2.setTitleCache("team2", true);
    Person person1 = Person.NewTitledInstance("person1");
    Person person2 = Person.NewTitledInstance("person2");
    team1.setNomenclaturalTitleCache("T.1", true);
    String street1 = "Strasse1";
    person1.setContact(Contact.NewInstance(street1, "12345", "Berlin", Country.ARGENTINAARGENTINEREPUBLIC(), "pobox", "Region", "a@b.de", "f12345", "+49-30-123456", URI.create("www.abc.de"), Point.NewInstance(2.4, 3.2, ReferenceSystem.WGS84(), 3)));
    team2.setContact(Contact.NewInstance("Street2", null, "London", null, null, null, null, "874599873", null, null, null));
    String street3 = "Street3";
    team2.addAddress(street3, null, null, null, null, null, Point.NewInstance(1.1, 2.2, null, 4));
    String emailAddress1 = "Email1";
    team1.addEmailAddress(emailAddress1);
    // FIXME
    // team2.addTeamMember(person1);
    team2.addTeamMember(person2);
    String emailAddress2 = "Email2";
    team2.addEmailAddress(emailAddress2);
    Credit credit1 = Credit.NewInstance(team2, "credit1");
    book1.addCredit(credit1);
    agentDao.save(team1);
    agentDao.save(team2);
    agentDao.save(person1);
    agentDao.save(person2);
    cdmGenericDao.save((Reference) book1);
    // starting condition
    name1.setCombinationAuthorship(person1);
    Assert.assertEquals("Name1 should have person1 as combination author", person1, name1.getCombinationAuthorship());
    DefaultMergeStrategy strategy = DefaultMergeStrategy.NewInstance(TeamOrPersonBase.class);
    // strategy.setOnlyReallocateLinks(true);
    FieldUnit fieldUnit1 = FieldUnit.NewInstance();
    fieldUnit1.setPrimaryCollector(person1);
    cdmGenericDao.save(fieldUnit1);
    try {
        cdmGenericDao.merge(team2, person1, strategy);
        Assert.fail("We expect exception because fieldunit.primaryCollector is of type person");
    } catch (MergeException e) {
        if (!e.getMessage().contains("Object can not be merged into new object as it is referenced in a way that does not allow merging")) {
            Assert.fail("The exception should be the one thrown by DeduplicationHelper.reallocateByHolder(...)");
        }
        // clean up for next test
        fieldUnit1.setPrimaryCollector(null);
    } catch (Exception e) {
        Assert.fail("Unhandled exception during merge");
    }
    Assert.assertEquals("Name1 should still have person1 as combination author", person1, name1.getCombinationAuthorship());
    // test collections
    team1.addTeamMember(person1);
    try {
        cdmGenericDao.merge(team2, person1, strategy);
        Assert.fail("We expect exception because fieldunit.primaryCollector is of type person");
    } catch (MergeException e) {
        if (!e.getMessage().contains("Object can not be merged into new object as it is referenced in a way that does not allow merging")) {
            Assert.fail("The exception should be the one thrown by DeduplicationHelper.reallocateByHolder(...)");
        }
        // clean up for next test
        team1.removeTeamMember(person1);
    } catch (Exception e) {
        Assert.fail("Unhandled exception during merge");
    }
    Assert.assertEquals("Name1 should still have person1 as combination author", person1, name1.getCombinationAuthorship());
    // test successful merge
    cdmGenericDao.save(name1);
    cdmGenericDao.merge(team2, person1, strategy);
    Assert.assertEquals("Name1 should have team2 as combination author now", team2, name1.getCombinationAuthorship());
}
Also used : DefaultMergeStrategy(eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) Credit(eu.etaxonomy.cdm.model.common.Credit) MergeException(eu.etaxonomy.cdm.strategy.merge.MergeException) IBook(eu.etaxonomy.cdm.model.reference.IBook) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Team(eu.etaxonomy.cdm.model.agent.Team) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) Person(eu.etaxonomy.cdm.model.agent.Person) FileNotFoundException(java.io.FileNotFoundException) MergeException(eu.etaxonomy.cdm.strategy.merge.MergeException) MatchException(eu.etaxonomy.cdm.strategy.match.MatchException) Test(org.junit.Test) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)

Example 4 with Credit

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

the class FullCoverageDataGenerator method createSupplemental.

private void createSupplemental(List<CdmBase> cdmBases) {
    Reference ref = ReferenceFactory.newBook();
    Annotation annotation = Annotation.NewDefaultLanguageInstance("annotation");
    ref.addAnnotation(annotation);
    handleAnnotatableEntity(annotation);
    Credit credit = Credit.NewInstance(Person.NewInstance(), "refCredit", "rc", Language.DEFAULT());
    ref.addCredit(credit);
    handleAnnotatableEntity(credit);
    Rights rights = Rights.NewInstance("My rights", Language.GERMAN());
    ref.addRights(rights);
    handleAnnotatableEntity(rights);
    // Others
    try {
        LSIDAuthority lsidAuthority = new LSIDAuthority("My authority");
        lsidAuthority.addNamespace("lsidNamespace", TaxonName.class);
        cdmBases.add(lsidAuthority);
    } catch (MalformedLSIDException e) {
        e.printStackTrace();
    }
    User user = User.NewInstance("myUser", "12345");
    Group group = Group.NewInstance("MyGroup");
    group.addMember(user);
    CdmAuthority authority = CdmAuthority.NewInstance(PermissionClass.TAXONNAME, "a property", Operation.CREATE, UUID.fromString("f1653cb8-5956-429e-852a-4a3b57893f49"));
    group.addAuthority(authority);
    Role role = Role.NewInstance("my role");
    user.addAuthority(role);
    cdmBases.add(user);
    cdmBases.add(group);
    cdmBases.add(authority);
    cdmBases.add(ref);
}
Also used : Role(eu.etaxonomy.cdm.model.permission.Role) Group(eu.etaxonomy.cdm.model.permission.Group) Rights(eu.etaxonomy.cdm.model.media.Rights) Credit(eu.etaxonomy.cdm.model.common.Credit) User(eu.etaxonomy.cdm.model.permission.User) MalformedLSIDException(com.ibm.lsid.MalformedLSIDException) Reference(eu.etaxonomy.cdm.model.reference.Reference) IntextReference(eu.etaxonomy.cdm.model.common.IntextReference) CdmAuthority(eu.etaxonomy.cdm.model.permission.CdmAuthority) LSIDAuthority(eu.etaxonomy.cdm.model.common.LSIDAuthority) Annotation(eu.etaxonomy.cdm.model.common.Annotation)

Example 5 with Credit

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

the class IdentifiableDaoBase method getCredits.

// @Override  //TODO add to interface, maybe add property path
public List<Credit> getCredits(T identifiableEntity, Integer pageSize, Integer pageNumber) {
    checkNotInPriorView("IdentifiableDaoBase.getCredits(T identifiableEntity, Integer pageSize, Integer pageNumber)");
    Query query = getSession().createQuery("select credits from " + type.getSimpleName() + " identifiableEntity join identifiableEntity.credits credits where identifiableEntity = :identifiableEntity");
    query.setParameter("identifiableEntity", identifiableEntity);
    setPagingParameter(query, pageSize, pageNumber);
    @SuppressWarnings("unchecked") List<Credit> result = query.list();
    return result;
}
Also used : Credit(eu.etaxonomy.cdm.model.common.Credit) Query(org.hibernate.Query) AuditQuery(org.hibernate.envers.query.AuditQuery)

Aggregations

Credit (eu.etaxonomy.cdm.model.common.Credit)7 Rights (eu.etaxonomy.cdm.model.media.Rights)4 Person (eu.etaxonomy.cdm.model.agent.Person)3 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)3 Test (org.junit.Test)3 MalformedLSIDException (com.ibm.lsid.MalformedLSIDException)2 Team (eu.etaxonomy.cdm.model.agent.Team)2 Annotation (eu.etaxonomy.cdm.model.common.Annotation)2 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)2 IntextReference (eu.etaxonomy.cdm.model.common.IntextReference)2 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)2 Media (eu.etaxonomy.cdm.model.media.Media)2 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)2 IBook (eu.etaxonomy.cdm.model.reference.IBook)2 Reference (eu.etaxonomy.cdm.model.reference.Reference)2 MetadataEntry (de.digitalcollections.iiif.model.MetadataEntry)1 PropertyValue (de.digitalcollections.iiif.model.PropertyValue)1 Address (eu.etaxonomy.cdm.model.agent.Address)1 Contact (eu.etaxonomy.cdm.model.agent.Contact)1