Search in sources :

Example 1 with JSONWorkExternalIdentifiers

use of org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers in project ORCID-Source by ORCID.

the class JSONWorkExternalIdentifiersConverterV1 method convertTo.

public String convertTo(WorkExternalIdentifiers messagePojo, WorkType workType) {
    JSONWorkExternalIdentifiers workExternalIdentifiers = new JSONWorkExternalIdentifiers();
    for (WorkExternalIdentifier workExternalIdentifier : messagePojo.getWorkExternalIdentifier()) {
        JSONWorkExternalIdentifier jsonWorkExternalIdentifier = new JSONWorkExternalIdentifier();
        if (workExternalIdentifier.getWorkExternalIdentifierType() != null) {
            jsonWorkExternalIdentifier.setWorkExternalIdentifierType(workExternalIdentifier.getWorkExternalIdentifierType().value());
        }
        if (workExternalIdentifier.getWorkExternalIdentifierId() != null && !PojoUtil.isEmpty(workExternalIdentifier.getWorkExternalIdentifierId().getContent())) {
            jsonWorkExternalIdentifier.setWorkExternalIdentifierId(new WorkExternalIdentifierId(workExternalIdentifier.getWorkExternalIdentifierId().getContent()));
        }
        WorkExternalIdentifierType type = WorkExternalIdentifierType.valueOf(conv.convertTo(jsonWorkExternalIdentifier.getWorkExternalIdentifierType(), null));
        if (org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.equals(type)) {
            if (!workType.equals(org.orcid.jaxb.model.message.WorkType.BOOK)) {
                jsonWorkExternalIdentifier.setRelationship(org.orcid.jaxb.model.record_rc1.Relationship.PART_OF.value());
            } else {
                jsonWorkExternalIdentifier.setRelationship(org.orcid.jaxb.model.record_rc1.Relationship.SELF.value());
            }
        } else if (org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISBN.equals(type)) {
            if (workType.equals(org.orcid.jaxb.model.message.WorkType.BOOK_CHAPTER) || workType.equals(org.orcid.jaxb.model.message.WorkType.CONFERENCE_PAPER)) {
                jsonWorkExternalIdentifier.setRelationship(org.orcid.jaxb.model.record_rc1.Relationship.PART_OF.value());
            } else {
                jsonWorkExternalIdentifier.setRelationship(org.orcid.jaxb.model.record_rc1.Relationship.SELF.value());
            }
        } else {
            jsonWorkExternalIdentifier.setRelationship(org.orcid.jaxb.model.record_rc1.Relationship.SELF.value());
        }
        workExternalIdentifiers.getWorkExternalIdentifier().add(jsonWorkExternalIdentifier);
    }
    return JsonUtils.convertToJsonString(workExternalIdentifiers);
}
Also used : WorkExternalIdentifierType(org.orcid.jaxb.model.message.WorkExternalIdentifierType) JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) WorkExternalIdentifierId(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier.WorkExternalIdentifierId) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier)

Example 2 with JSONWorkExternalIdentifiers

use of org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers in project ORCID-Source by ORCID.

the class JSONWorkExternalIdentifiersConverterV2 method convertFrom.

@Override
public ExternalIDs convertFrom(String source, Type<ExternalIDs> destinationType) {
    JSONWorkExternalIdentifiers workExternalIdentifiers = JsonUtils.readObjectFromJsonString(source, JSONWorkExternalIdentifiers.class);
    ExternalIDs externalIDs = new ExternalIDs();
    for (JSONWorkExternalIdentifier workExternalIdentifier : workExternalIdentifiers.getWorkExternalIdentifier()) {
        ExternalID id = new ExternalID();
        if (workExternalIdentifier.getWorkExternalIdentifierType() == null) {
            id.setType(WorkExternalIdentifierType.OTHER_ID.value());
        } else {
            id.setType(conv.convertFrom(workExternalIdentifier.getWorkExternalIdentifierType(), null));
        }
        if (workExternalIdentifier.getWorkExternalIdentifierId() != null) {
            id.setValue(workExternalIdentifier.getWorkExternalIdentifierId().content);
        }
        if (workExternalIdentifier.getUrl() != null) {
            id.setUrl(new Url(workExternalIdentifier.getUrl().getValue()));
        }
        if (workExternalIdentifier.getRelationship() != null) {
            id.setRelationship(Relationship.fromValue(conv.convertFrom(workExternalIdentifier.getRelationship(), null)));
        }
        externalIDs.getExternalIdentifier().add(id);
    }
    return externalIDs;
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier) Url(org.orcid.jaxb.model.common_v2.Url) JSONUrl(org.orcid.core.adapter.jsonidentifier.JSONUrl)

Example 3 with JSONWorkExternalIdentifiers

use of org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers in project ORCID-Source by ORCID.

the class JSONWorkExternalIdentifiersConverterV3 method convertTo.

@Override
public String convertTo(ExternalIDs source, Type<String> destinationType) {
    JSONWorkExternalIdentifiers jsonWorkExternalIdentifiers = new JSONWorkExternalIdentifiers();
    for (ExternalID externalID : source.getExternalIdentifier()) {
        JSONWorkExternalIdentifier jsonWorkExternalIdentifier = new JSONWorkExternalIdentifier();
        if (externalID.getType() != null) {
            jsonWorkExternalIdentifier.setWorkExternalIdentifierType(conv.convertTo(externalID.getType(), null));
        }
        if (externalID.getUrl() != null) {
            jsonWorkExternalIdentifier.setUrl(new JSONUrl(externalID.getUrl().getValue()));
        }
        if (!PojoUtil.isEmpty(externalID.getValue())) {
            jsonWorkExternalIdentifier.setWorkExternalIdentifierId(new WorkExternalIdentifierId(externalID.getValue()));
        }
        if (externalID.getRelationship() != null) {
            jsonWorkExternalIdentifier.setRelationship(conv.convertTo(externalID.getRelationship().value(), null));
        }
        jsonWorkExternalIdentifiers.getWorkExternalIdentifier().add(jsonWorkExternalIdentifier);
    }
    return JsonUtils.convertToJsonString(jsonWorkExternalIdentifiers);
}
Also used : JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) WorkExternalIdentifierId(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier.WorkExternalIdentifierId) JSONUrl(org.orcid.core.adapter.jsonidentifier.JSONUrl) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier)

Example 4 with JSONWorkExternalIdentifiers

use of org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers in project ORCID-Source by ORCID.

the class JSONWorkExternalIdentifiersConverterV3 method convertFrom.

@Override
public ExternalIDs convertFrom(String source, Type<ExternalIDs> destinationType) {
    JSONWorkExternalIdentifiers workExternalIdentifiers = JsonUtils.readObjectFromJsonString(source, JSONWorkExternalIdentifiers.class);
    ExternalIDs externalIDs = new ExternalIDs();
    for (JSONWorkExternalIdentifier workExternalIdentifier : workExternalIdentifiers.getWorkExternalIdentifier()) {
        ExternalID id = new ExternalID();
        if (workExternalIdentifier.getWorkExternalIdentifierType() == null) {
            id.setType(WorkExternalIdentifierType.OTHER_ID.value());
        } else {
            id.setType(conv.convertFrom(workExternalIdentifier.getWorkExternalIdentifierType(), null));
        }
        if (workExternalIdentifier.getWorkExternalIdentifierId() != null) {
            id.setValue(workExternalIdentifier.getWorkExternalIdentifierId().content);
            // note, uses API type name.
            id.setNormalized(new TransientNonEmptyString(norm.normalise(id.getType(), workExternalIdentifier.getWorkExternalIdentifierId().content)));
            if (StringUtils.isEmpty(id.getNormalized().getValue())) {
                id.setNormalizedError(new TransientError(localeManager.resolveMessage("transientError.normalization_failed.code"), localeManager.resolveMessage("transientError.normalization_failed.message", id.getType(), workExternalIdentifier.getWorkExternalIdentifierId().content)));
            }
        }
        if (workExternalIdentifier.getUrl() != null) {
            id.setUrl(new Url(workExternalIdentifier.getUrl().getValue()));
        }
        if (workExternalIdentifier.getRelationship() != null) {
            id.setRelationship(Relationship.fromValue(conv.convertFrom(workExternalIdentifier.getRelationship(), null)));
        }
        externalIDs.getExternalIdentifier().add(id);
    }
    return externalIDs;
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) TransientError(org.orcid.jaxb.model.v3.dev1.common.TransientError) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) JSONUrl(org.orcid.core.adapter.jsonidentifier.JSONUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url)

Example 5 with JSONWorkExternalIdentifiers

use of org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers in project ORCID-Source by ORCID.

the class JSONWorkExternalIdentifiersConverterV1 method convertFrom.

public WorkExternalIdentifiers convertFrom(String source) {
    JSONWorkExternalIdentifiers jsonWorkExternalIdentifiers = JsonUtils.readObjectFromJsonString(source, JSONWorkExternalIdentifiers.class);
    WorkExternalIdentifiers workExternalIdentifiers = new WorkExternalIdentifiers();
    for (JSONWorkExternalIdentifier jsonWorkExternalIdentifier : jsonWorkExternalIdentifiers.getWorkExternalIdentifier()) {
        WorkExternalIdentifier workExternalIdentifier = new WorkExternalIdentifier();
        try {
            workExternalIdentifier.setWorkExternalIdentifierType(WorkExternalIdentifierType.fromValue(conv.convertFrom(jsonWorkExternalIdentifier.getWorkExternalIdentifierType(), null)));
        } catch (Exception e) {
            workExternalIdentifier.setWorkExternalIdentifierType(WorkExternalIdentifierType.OTHER_ID);
        }
        workExternalIdentifier.setWorkExternalIdentifierId(new org.orcid.jaxb.model.message.WorkExternalIdentifierId());
        if (jsonWorkExternalIdentifier.getWorkExternalIdentifierId() != null) {
            workExternalIdentifier.getWorkExternalIdentifierId().setContent(jsonWorkExternalIdentifier.getWorkExternalIdentifierId().content);
        }
        workExternalIdentifiers.getWorkExternalIdentifier().add(workExternalIdentifier);
    }
    return workExternalIdentifiers;
}
Also used : WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) JSONWorkExternalIdentifiers(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier) JSONWorkExternalIdentifier(org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier)

Aggregations

JSONWorkExternalIdentifier (org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier)6 JSONWorkExternalIdentifiers (org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifiers)6 JSONUrl (org.orcid.core.adapter.jsonidentifier.JSONUrl)4 WorkExternalIdentifierId (org.orcid.core.adapter.jsonidentifier.JSONWorkExternalIdentifier.WorkExternalIdentifierId)3 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)2 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)2 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)2 Url (org.orcid.jaxb.model.common_v2.Url)1 WorkExternalIdentifierType (org.orcid.jaxb.model.message.WorkExternalIdentifierType)1 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)1 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)1 TransientError (org.orcid.jaxb.model.v3.dev1.common.TransientError)1 TransientNonEmptyString (org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)1 Url (org.orcid.jaxb.model.v3.dev1.common.Url)1 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)1