Search in sources :

Example 26 with Visibility

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

the class ValidateV2RC4Identifiers method testPerson.

/**
     * <external-identifier:external-identifiers>
                <external-identifier:external-identifier visibility="public" put-code="1">
                        <common:external-id-type>type-1</common:external-id-type>
                        <common:external-id-value>value-1</common:external-id-value>
                        <common:external-id-url>http://url.com/1</common:external-id-url>
                        <common:created-date>2001-12-31T12:00:00</common:created-date>
                        <common:last-modified-date>2001-12-31T12:00:00</common:last-modified-date>
                        <common:source>
                                <common:source-orcid>
                                        <common:uri>http://orcid.org/8888-8888-8888-8880</common:uri>
                                        <common:path>8888-8888-8888-8880</common:path>
                                        <common:host>orcid.org</common:host>
                                </common:source-orcid>
                                <common:source-name />
                        </common:source>
                </external-identifier:external-identifier>
        </external-identifier:external-identifiers>
        
     * @throws SAXException
     * @throws IOException
     * @throws JAXBException
     * @throws ParserConfigurationException
     */
@Test
public void testPerson() throws SAXException, IOException, JAXBException, ParserConfigurationException {
    Person person = unmarshallFromPath("/record_2.0_rc4/samples/person-2.0_rc4.xml", Person.class);
    assertEquals("credit-name", person.getName().getCreditName().getContent());
    assertEquals(1, person.getExternalIdentifiers().getExternalIdentifiers().size());
    PersonExternalIdentifier id = person.getExternalIdentifiers().getExternalIdentifiers().get(0);
    assertEquals("type-1", id.getType());
    assertEquals("value-1", id.getValue());
    assertEquals(new Url("http://url.com/1"), id.getUrl());
    assertNull(id.getRelationship());
    assertNotNull(id.getCreatedDate().getValue());
    assertNotNull(id.getLastModifiedDate().getValue());
    assertEquals(new Long(1), id.getPutCode());
    assertEquals(Visibility.PUBLIC, id.getVisibility());
    Validator validator = getValidator("person");
    validator.validate(marshall(Person.class, person));
    validator.validate(marshallToDOM(Person.class, person));
}
Also used : PersonExternalIdentifier(org.orcid.jaxb.model.record_rc4.PersonExternalIdentifier) Person(org.orcid.jaxb.model.record_rc4.Person) Url(org.orcid.jaxb.model.common_rc4.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 27 with Visibility

use of org.orcid.jaxb.model.common_rc4.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 28 with Visibility

use of org.orcid.jaxb.model.common_rc4.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 29 with Visibility

use of org.orcid.jaxb.model.common_rc4.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 30 with Visibility

use of org.orcid.jaxb.model.common_rc4.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)

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