Search in sources :

Example 71 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateGroupId_invalidGroupIdTest.

@Test(expected = OrcidValidationException.class)
public void validateGroupId_invalidGroupIdTest() {
    SourceEntity source = mock(SourceEntity.class);
    when(source.getSourceName()).thenReturn("source name");
    GroupIdRecord g = getGroupIdRecord();
    g.setGroupId("invalid");
    activityValidator.validateGroupIdRecord(g, true, source);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) Test(org.junit.Test)

Example 72 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validatePeerReview_invalidPutCodeTest.

@Test(expected = InvalidPutCodeException.class)
public void validatePeerReview_invalidPutCodeTest() {
    SourceEntity source = mock(SourceEntity.class);
    when(source.getSourceName()).thenReturn("source name");
    PeerReview pr = getPeerReview();
    pr.setPutCode(1L);
    activityValidator.validatePeerReview(pr, source, true, true, Visibility.PUBLIC);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 73 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class ExternalIdentifierManagerImpl method createExternalIdentifier.

@Override
public PersonExternalIdentifier createExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate external identifier
    PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, true, isApiRequest, null, requireRelationshipOnExternalIdentifier);
    // Validate it is not duplicated
    List<ExternalIdentifierEntity> existingExternalIdentifiers = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
    for (ExternalIdentifierEntity existing : existingExternalIdentifiers) {
        if (isDuplicated(existing, externalIdentifier, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "external-identifier");
            params.put("value", externalIdentifier.getUrl().getValue());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    ExternalIdentifierEntity newEntity = jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    newEntity.setOwner(profile);
    newEntity.setDateCreated(new Date());
    if (sourceEntity.getSourceProfile() != null) {
        newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    setIncomingPrivacy(newEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
    externalIdentifierDao.persist(newEntity);
    return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(newEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 74 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class AffiliationsManagerImpl method createEmploymentAffiliation.

/**
     * Add a new employment to the given user
     * 
     * @param orcid
     *            The user to add the employment
     * @param employment
     *            The employment to add
     * @return the added employment
     * */
@Override
public Employment createEmploymentAffiliation(String orcid, Employment employment, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateEmployment(employment, sourceEntity, true, isApiRequest, null);
    OrgAffiliationRelationEntity employmentEntity = jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity(employment);
    // Updates the give organization with the latest organization from
    // database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(employment);
    employmentEntity.setOrg(updatedOrganization);
    // Set source id 
    if (sourceEntity.getSourceProfile() != null) {
        employmentEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        employmentEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    employmentEntity.setProfile(profile);
    setIncomingWorkPrivacy(employmentEntity, profile);
    employmentEntity.setAffiliationType(AffiliationType.EMPLOYMENT);
    orgAffiliationRelationDao.persist(employmentEntity);
    orgAffiliationRelationDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItem(employmentEntity));
    return jpaJaxbEmploymentAdapter.toEmployment(employmentEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 75 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class AffiliationsManagerImpl method createEducationAffiliation.

/**
     * Add a new education to the given user
     * 
     * @param orcid
     *            The user to add the education
     * @param education
     *            The education to add
     * @return the added education
     * */
@Override
public Education createEducationAffiliation(String orcid, Education education, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateEducation(education, sourceEntity, true, isApiRequest, null);
    OrgAffiliationRelationEntity educationEntity = jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity(education);
    // Updates the give organization with the latest organization from
    // database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(education);
    educationEntity.setOrg(updatedOrganization);
    // Set source id 
    if (sourceEntity.getSourceProfile() != null) {
        educationEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        educationEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    educationEntity.setProfile(profile);
    setIncomingWorkPrivacy(educationEntity, profile);
    educationEntity.setAffiliationType(AffiliationType.EDUCATION);
    orgAffiliationRelationDao.persist(educationEntity);
    orgAffiliationRelationDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItem(educationEntity));
    return jpaJaxbEducationAdapter.toEducation(educationEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)111 Test (org.junit.Test)58 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)57 BaseTest (org.orcid.core.BaseTest)44 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)28 Date (java.util.Date)19 HashMap (java.util.HashMap)15 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)14 Work (org.orcid.jaxb.model.record_v2.Work)14 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)13 Visibility (org.orcid.jaxb.model.common_v2.Visibility)12 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Funding (org.orcid.jaxb.model.record_v2.Funding)10 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)6 WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)6 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)5