Search in sources :

Example 16 with Deprecated

use of org.orcid.jaxb.model.record_v2.Deprecated in project ORCID-Source by ORCID.

the class MongoMessageProcessorTest method testDeprecated.

@Test
public void testDeprecated() throws LockedRecordException, DeprecatedRecordException {
    when(mock_orcid20ApiClient.fetchPublicRecord(Matchers.any())).thenThrow(new DeprecatedRecordException(new OrcidError()));
    LastModifiedMessage m = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m);
    // test db has entry for depreciated record
    Document d = new Document();
    d.put("_id", this.orcid);
    assertEquals(col.count(d), 1);
    FindIterable<Document> it = col.find(d);
    assertEquals(it.first().get("status"), "deprecated");
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) Document(org.bson.Document) Date(java.util.Date) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) Test(org.junit.Test)

Example 17 with Deprecated

use of org.orcid.jaxb.model.record_v2.Deprecated in project ORCID-Source by ORCID.

the class MongoMessageProcessor method updateMongo.

private void updateMongo(BaseMessage message) {
    String orcid = message.getOrcid();
    LOG.info("Updating using Record " + orcid + " in Mongo");
    try {
        Record record = orcid20ApiClient.fetchPublicRecord(message);
        // Remove deactivated records from Mongo
        if (record.getHistory() != null && record.getHistory().getDeactivationDate() != null && record.getHistory().getDeactivationDate().getValue() != null) {
            delete(message.getOrcid(), "deactivated");
            return;
        }
        Document d = Document.parse(mapper.writeValueAsString(record));
        d.put("_id", message.getOrcid());
        Document index = new Document();
        index.put("_id", message.getOrcid());
        col.replaceOne(index, d, upsert);
        recordStatusManager.markAsSent(orcid, AvailableBroker.MONGO);
    } catch (LockedRecordException lre) {
        LOG.error("Record " + orcid + " is locked");
        delete(message.getOrcid(), "locked");
    } catch (DeprecatedRecordException dre) {
        LOG.error("Record " + orcid + " is deprecated");
        delete(message.getOrcid(), "deprecated");
    } catch (Exception e) {
        LOG.error("pants", e);
        recordStatusManager.markAsFailed(message.getOrcid(), AvailableBroker.MONGO);
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Record(org.orcid.jaxb.model.record_v2.Record) Document(org.bson.Document) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) MongoException(com.mongodb.MongoException)

Example 18 with Deprecated

use of org.orcid.jaxb.model.record_v2.Deprecated in project ORCID-Source by ORCID.

the class ActivitiesGroup method belongsToGroup.

@Deprecated
public /**
 * This method is only used by tests to confirm accuracy of ActivitiesGroupGenerator and should not be used in production
 *
 * @param activity
 * @return
 */
boolean belongsToGroup(GroupableActivity activity) {
    boolean isPeerReview = PeerReviewSummary.class.isAssignableFrom(activity.getClass());
    // If there are no grouping keys
    if (groupKeys == null || groupKeys.isEmpty()) {
        if (isPeerReview) {
            return false;
        } else {
            if (activity.getExternalIdentifiers() == null || activity.getExternalIdentifiers().getExternalIdentifier() == null || activity.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
                // If the activity doesn't have any external identifier, check if the activity is in the group
                if (activities.contains(activity))
                    return true;
                else
                    return false;
            } else {
                // If any of the activities pass the grouping validation, the activity must belong to other group
                for (GroupAble extId : activity.getExternalIdentifiers().getExternalIdentifier()) {
                    if (extId.isGroupAble())
                        return false;
                }
                // If none of the activities pass the groupings validation, so, lets check if the group actually contains the activity
                if (activities.contains(activity))
                    return true;
                else
                    return false;
            }
        }
    }
    if (isPeerReview) {
        PeerReviewSummary peerReviewSummary = (PeerReviewSummary) activity;
        PeerReviewGroupKey prgk = new PeerReviewGroupKey();
        prgk.setGroupId(peerReviewSummary.getGroupId());
        if (prgk.isGroupAble()) {
            if (groupKeys.contains(prgk)) {
                return true;
            }
        }
    } else {
        // Check existing keys
        ExternalIdentifiersContainer container = activity.getExternalIdentifiers();
        if (container != null) {
            List<? extends GroupAble> extIds = (List<? extends GroupAble>) container.getExternalIdentifier();
            for (GroupAble extId : extIds) {
                // First check keys restrictions
                if (extId.isGroupAble()) {
                    // If any of the keys already exists on this group, return true
                    if (containsKey(extId))
                        return true;
                }
            }
        }
    }
    return false;
}
Also used : PeerReviewGroupKey(org.orcid.jaxb.model.record.summary_v2.PeerReviewGroupKey) PeerReviewSummary(org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary) ExternalIdentifiersContainer(org.orcid.jaxb.model.record_v2.ExternalIdentifiersContainer) List(java.util.List) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Aggregations

IOException (java.io.IOException)7 DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)6 InputStreamReader (java.io.InputStreamReader)5 Reader (java.io.Reader)5 Test (org.junit.Test)5 LockedRecordException (org.orcid.listener.exception.LockedRecordException)5 Biography (org.orcid.jaxb.model.record_v2.Biography)4 ArrayList (java.util.ArrayList)3 JAXBException (javax.xml.bind.JAXBException)3 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)3 Deprecated (org.orcid.jaxb.model.record_rc2.Deprecated)3 Address (org.orcid.jaxb.model.record_v2.Address)3 CreditName (org.orcid.jaxb.model.record_v2.CreditName)3 Funding (org.orcid.jaxb.model.record_v2.Funding)3 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)3 AmazonClientException (com.amazonaws.AmazonClientException)2 List (java.util.List)2 Document (org.bson.Document)2 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)2 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)2