Search in sources :

Example 46 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class OrcidSecurityManagerTestBase method createEmail.

protected Email createEmail(Visibility v, String sourceId) {
    Email email = new Email();
    email.setEmail("test-email-" + System.currentTimeMillis() + "@test.orcid.org");
    email.setVisibility(v);
    setSource(email, sourceId);
    return email;
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email)

Example 47 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class OrcidSecurityManagerTestBase method createServiceSummary.

protected ServiceSummary createServiceSummary(Visibility v, String sourceId) {
    ServiceSummary e = new ServiceSummary();
    e.setVisibility(v);
    setSource(e, sourceId);
    return e;
}
Also used : ServiceSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary)

Example 48 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class ExternalIdentifierManagerImpl method updateExternalIdentifier.

@Override
public PersonExternalIdentifier updateExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ExternalIdentifierEntity updatedExternalIdentifierEntity = externalIdentifierDao.getExternalIdentifierEntity(orcid, externalIdentifier.getPutCode());
    // Save the original source
    String existingSourceId = updatedExternalIdentifierEntity.getSourceId();
    String existingClientSourceId = updatedExternalIdentifierEntity.getClientSourceId();
    Visibility originalVisibility = Visibility.fromValue(updatedExternalIdentifierEntity.getVisibility().value());
    // Validate external identifier
    PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, false, isApiRequest, originalVisibility, 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);
        }
    }
    orcidSecurityManager.checkSource(updatedExternalIdentifierEntity);
    jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier, updatedExternalIdentifierEntity);
    updatedExternalIdentifierEntity.setLastModified(new Date());
    // Set source
    updatedExternalIdentifierEntity.setSourceId(existingSourceId);
    updatedExternalIdentifierEntity.setClientSourceId(existingClientSourceId);
    externalIdentifierDao.merge(updatedExternalIdentifierEntity);
    return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(updatedExternalIdentifierEntity);
}
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) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Date(java.util.Date)

Example 49 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class AffiliationsManagerImpl method updateAffiliation.

public Affiliation updateAffiliation(String orcid, Affiliation affiliation, boolean isApiRequest, AffiliationType type) {
    OrgAffiliationRelationEntity entity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, affiliation.getPutCode());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = entity.getSourceId();
    String existingClientSourceId = entity.getClientSourceId();
    org.orcid.jaxb.model.common_v2.Visibility originalVisibility = entity.getVisibility();
    orcidSecurityManager.checkSource(entity);
    activityValidator.validateAffiliation(affiliation, sourceEntity, false, isApiRequest, org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(originalVisibility.value()));
    if (isApiRequest) {
        checkAffiliationExternalIDsForDuplicates(orcid, affiliation, sourceEntity);
    }
    switch(type) {
        case DISTINCTION:
            jpaJaxbDistinctionAdapter.toOrgAffiliationRelationEntity((Distinction) affiliation, entity);
            break;
        case EDUCATION:
            jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity((Education) affiliation, entity);
            break;
        case EMPLOYMENT:
            jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity((Employment) affiliation, entity);
            break;
        case INVITED_POSITION:
            jpaJaxbInvitedPositionAdapter.toOrgAffiliationRelationEntity((InvitedPosition) affiliation, entity);
            break;
        case MEMBERSHIP:
            jpaJaxbMembershipAdapter.toOrgAffiliationRelationEntity((Membership) affiliation, entity);
            break;
        case QUALIFICATION:
            jpaJaxbQualificationAdapter.toOrgAffiliationRelationEntity((Qualification) affiliation, entity);
            break;
        case SERVICE:
            jpaJaxbServiceAdapter.toOrgAffiliationRelationEntity((Service) affiliation, entity);
            break;
    }
    entity.setVisibility(originalVisibility);
    // Be sure it doesn't overwrite the source
    entity.setSourceId(existingSourceId);
    entity.setClientSourceId(existingClientSourceId);
    // Updates the give organization with the latest organization from
    // database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(affiliation);
    entity.setOrg(updatedOrganization);
    entity.setAffiliationType(type);
    entity = orgAffiliationRelationDao.merge(entity);
    orgAffiliationRelationDao.flush();
    Affiliation result = null;
    switch(type) {
        case DISTINCTION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity));
            result = jpaJaxbDistinctionAdapter.toDistinction(entity);
            break;
        case EDUCATION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity));
            result = jpaJaxbEducationAdapter.toEducation(entity);
            break;
        case EMPLOYMENT:
            notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity));
            result = jpaJaxbEmploymentAdapter.toEmployment(entity);
            break;
        case INVITED_POSITION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity));
            result = jpaJaxbInvitedPositionAdapter.toInvitedPosition(entity);
            break;
        case MEMBERSHIP:
            notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity));
            result = jpaJaxbMembershipAdapter.toMembership(entity);
            break;
        case QUALIFICATION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity));
            result = jpaJaxbQualificationAdapter.toQualification(entity);
            break;
        case SERVICE:
            notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity));
            result = jpaJaxbServiceAdapter.toService(entity);
            break;
    }
    return result;
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation)

Example 50 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class OtherNameManagerImpl method updateOtherName.

@Override
@Transactional
public OtherName updateOtherName(String orcid, Long putCode, OtherName otherName, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    OtherNameEntity updatedOtherNameEntity = otherNameDao.getOtherName(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedOtherNameEntity.getVisibility().value());
    // Save the original source
    String existingSourceId = updatedOtherNameEntity.getSourceId();
    String existingClientSourceId = updatedOtherNameEntity.getClientSourceId();
    // Validate the other name
    PersonValidator.validateOtherName(otherName, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    for (OtherNameEntity existing : existingOtherNames) {
        if (isDuplicated(existing, otherName, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "otherName");
            params.put("value", otherName.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedOtherNameEntity);
    jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName, updatedOtherNameEntity);
    updatedOtherNameEntity.setLastModified(new Date());
    // Be sure it doesn't overwrite the source
    updatedOtherNameEntity.setSourceId(existingSourceId);
    updatedOtherNameEntity.setClientSourceId(existingClientSourceId);
    otherNameDao.merge(updatedOtherNameEntity);
    return jpaJaxbOtherNameAdapter.toOtherName(updatedOtherNameEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)44 ClientResponse (com.sun.jersey.api.client.ClientResponse)17 Test (org.junit.Test)17 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Url (org.orcid.jaxb.model.v3.dev1.common.Url)11 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)11 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)11 HashMap (java.util.HashMap)10 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)10 Name (org.orcid.jaxb.model.v3.dev1.record.Name)7 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)7 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)6 Work (org.orcid.jaxb.model.v3.dev1.record.Work)6 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)6 Date (java.util.Date)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5