Search in sources :

Example 26 with Visibility

use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.

the class WorksController method initializeFields.

private void initializeFields(WorkForm w) {
    if (w.getVisibility() == null) {
        ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
        Visibility v = profile.getActivitiesVisibilityDefault() == null ? Visibility.fromValue(OrcidVisibilityDefaults.WORKS_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault();
        w.setVisibility(v);
    }
    if (w.getTitle() == null) {
        w.setTitle(new Text());
    }
    if (w.getSubtitle() == null) {
        w.setSubtitle(new Text());
    }
    if (w.getTranslatedTitle() == null) {
        TranslatedTitleForm tt = new TranslatedTitleForm();
        tt.setContent(new String());
        tt.setLanguageCode(new String());
        tt.setLanguageName(new String());
        w.setTranslatedTitle(tt);
    }
    if (PojoUtil.isEmpty(w.getJournalTitle())) {
        Text jt = new Text();
        jt.setRequired(false);
        w.setJournalTitle(jt);
    }
    if (PojoUtil.isEmpty(w.getWorkCategory())) {
        Text wCategoryText = new Text();
        wCategoryText.setValue(new String());
        wCategoryText.setRequired(true);
        w.setWorkCategory(wCategoryText);
    }
    if (PojoUtil.isEmpty(w.getWorkType())) {
        Text wTypeText = new Text();
        wTypeText.setValue(new String());
        wTypeText.setRequired(true);
        w.setWorkType(wTypeText);
    }
    initializePublicationDate(w);
    if (w.getWorkExternalIdentifiers() == null || w.getWorkExternalIdentifiers().isEmpty()) {
        WorkExternalIdentifier wei = new WorkExternalIdentifier();
        Text wdiType = new Text();
        wdiType.setValue(new String());
        wei.setWorkExternalIdentifierId(new Text());
        wei.setWorkExternalIdentifierType(wdiType);
        wei.setRelationship(Text.valueOf(Relationship.SELF.value()));
        List<WorkExternalIdentifier> wdiL = new ArrayList<WorkExternalIdentifier>();
        wdiL.add(wei);
        w.setWorkExternalIdentifiers(wdiL);
    }
    if (PojoUtil.isEmpty(w.getUrl())) {
        w.setUrl(new Text());
    }
    if (w.getContributors() == null || w.getContributors().isEmpty()) {
        List<Contributor> contrList = new ArrayList<Contributor>();
        w.setContributors(contrList);
    }
    if (PojoUtil.isEmpty(w.getShortDescription())) {
        w.setShortDescription(new Text());
    }
    if (PojoUtil.isEmpty(w.getLanguageCode())) {
        Text lc = new Text();
        lc.setRequired(false);
        w.setLanguageCode(lc);
    }
    if (PojoUtil.isEmpty(w.getLanguageName())) {
        Text ln = new Text();
        ln.setRequired(false);
        w.setLanguageName(ln);
    }
    if (PojoUtil.isEmpty(w.getCountryCode())) {
        w.setCountryCode(new Text());
    }
    if (PojoUtil.isEmpty(w.getCountryName())) {
        w.setCountryName(new Text());
    }
}
Also used : ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Text(org.orcid.pojo.ajaxForm.Text) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm)

Example 27 with Visibility

use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.

the class AddressManagerImpl method updateAddress.

@Override
@Transactional
public Address updateAddress(String orcid, Long putCode, Address address, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    AddressEntity updatedEntity = addressDao.getAddress(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
    //Save the original source
    String existingSourceId = updatedEntity.getSourceId();
    String existingClientSourceId = updatedEntity.getClientSourceId();
    //If it is an update from the API, check the source and preserve the original visibility
    if (isApiRequest) {
        orcidSecurityManager.checkSource(updatedEntity);
    }
    // Validate the address
    PersonValidator.validateAddress(address, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<AddressEntity> existingAddresses = addressDao.getAddresses(orcid, getLastModified(orcid));
    for (AddressEntity existing : existingAddresses) {
        //If it is not the same element
        if (!existing.getId().equals(address.getPutCode())) {
            if (isDuplicated(existing, address, sourceEntity)) {
                Map<String, String> params = new HashMap<String, String>();
                params.put("type", "address");
                params.put("value", address.getCountry().getValue().value());
                throw new OrcidDuplicatedElementException(params);
            }
        }
    }
    adapter.toAddressEntity(address, updatedEntity);
    updatedEntity.setLastModified(new Date());
    //Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    addressDao.merge(updatedEntity);
    return adapter.toAddress(updatedEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Example 28 with Visibility

use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.

the class AddressManagerImpl method setIncomingPrivacy.

private void setIncomingPrivacy(AddressEntity entity, ProfileEntity profile) {
    org.orcid.jaxb.model.common_v2.Visibility incomingCountryVisibility = entity.getVisibility();
    org.orcid.jaxb.model.common_v2.Visibility defaultCountryVisibility = (profile.getActivitiesVisibilityDefault() == null) ? org.orcid.jaxb.model.common_v2.Visibility.PRIVATE : org.orcid.jaxb.model.common_v2.Visibility.fromValue(profile.getActivitiesVisibilityDefault().value());
    if (profile.getClaimed() != null && profile.getClaimed()) {
        entity.setVisibility(defaultCountryVisibility);
    } else if (incomingCountryVisibility == null) {
        entity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
    }
}
Also used : Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 29 with Visibility

use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.

the class ExternalIdentifierManagerImpl method setIncomingPrivacy.

private void setIncomingPrivacy(ExternalIdentifierEntity entity, ProfileEntity profile) {
    org.orcid.jaxb.model.common_v2.Visibility incomingExternalIdentifierVisibility = entity.getVisibility();
    org.orcid.jaxb.model.common_v2.Visibility defaultExternalIdentifierVisibility = (profile.getActivitiesVisibilityDefault() == null) ? org.orcid.jaxb.model.common_v2.Visibility.PRIVATE : org.orcid.jaxb.model.common_v2.Visibility.fromValue(profile.getActivitiesVisibilityDefault().value());
    if (profile.getClaimed() != null && profile.getClaimed()) {
        entity.setVisibility(defaultExternalIdentifierVisibility);
    } else if (incomingExternalIdentifierVisibility == null) {
        entity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
    }
}
Also used : Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 30 with Visibility

use of org.orcid.jaxb.model.common_rc3.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.common_v2.Visibility) Date(java.util.Date)

Aggregations

Visibility (org.orcid.jaxb.model.common_v2.Visibility)55 Test (org.junit.Test)36 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 HashMap (java.util.HashMap)10 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)10 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)9 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)8 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)8 Date (java.util.Date)7 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)7 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)6 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5 Funding (org.orcid.jaxb.model.record_v2.Funding)5 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)5 Work (org.orcid.jaxb.model.record_v2.Work)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)4 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)4 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4