Search in sources :

Example 1 with PeerReviewEntity

use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.

the class PeerReviewDaoImpl method getPeerReview.

@Override
public PeerReviewEntity getPeerReview(String userOrcid, Long peerReviewId) {
    Query query = entityManager.createQuery("from PeerReviewEntity where profile.id=:userOrcid and id=:peerReviewId");
    query.setParameter("userOrcid", userOrcid);
    query.setParameter("peerReviewId", Long.valueOf(peerReviewId));
    return (PeerReviewEntity) query.getSingleResult();
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity)

Example 2 with PeerReviewEntity

use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getPeerReviewMapperFacade.

public MapperFacade getPeerReviewMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ConverterFactory converterFactory = mapperFactory.getConverterFactory();
    converterFactory.registerConverter("workExternalIdentifiersConverterId", new WorkExternalIDsConverter());
    converterFactory.registerConverter("workExternalIdentifierConverterId", new PeerReviewWorkExternalIDConverter());
    //do same as work
    ClassMapBuilder<PeerReview, PeerReviewEntity> classMap = mapperFactory.classMap(PeerReview.class, PeerReviewEntity.class);
    addV2CommonFields(classMap);
    registerSourceConverters(mapperFactory, classMap);
    classMap.field("url.value", "url");
    classMap.field("organization.name", "org.name");
    classMap.field("organization.address.city", "org.city");
    classMap.field("organization.address.region", "org.region");
    classMap.field("organization.address.country", "org.country");
    classMap.field("organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier", "org.orgDisambiguated.sourceId");
    classMap.field("organization.disambiguatedOrganization.disambiguationSource", "org.orgDisambiguated.sourceType");
    classMap.field("groupId", "groupId");
    classMap.field("subjectType", "subjectType");
    classMap.field("subjectUrl.value", "subjectUrl");
    classMap.field("subjectName.title.content", "subjectName");
    classMap.field("subjectName.translatedTitle.content", "subjectTranslatedName");
    classMap.field("subjectName.translatedTitle.languageCode", "subjectTranslatedNameLanguageCode");
    classMap.field("subjectContainerName.content", "subjectContainerName");
    classMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
    classMap.fieldMap("subjectExternalIdentifier", "subjectExternalIdentifiersJson").converter("workExternalIdentifierConverterId").add();
    classMap.register();
    ClassMapBuilder<PeerReviewSummary, PeerReviewEntity> peerReviewSummaryClassMap = mapperFactory.classMap(PeerReviewSummary.class, PeerReviewEntity.class);
    addV2CommonFields(peerReviewSummaryClassMap);
    registerSourceConverters(mapperFactory, peerReviewSummaryClassMap);
    peerReviewSummaryClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("workExternalIdentifiersConverterId").add();
    peerReviewSummaryClassMap.field("organization.name", "org.name");
    peerReviewSummaryClassMap.field("organization.address.city", "org.city");
    peerReviewSummaryClassMap.field("organization.address.region", "org.region");
    peerReviewSummaryClassMap.field("organization.address.country", "org.country");
    peerReviewSummaryClassMap.field("organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier", "org.orgDisambiguated.sourceId");
    peerReviewSummaryClassMap.field("organization.disambiguatedOrganization.disambiguationSource", "org.orgDisambiguated.sourceType");
    peerReviewSummaryClassMap.register();
    mapperFactory.classMap(FuzzyDate.class, CompletionDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
    return mapperFactory.getMapperFacade();
}
Also used : PeerReviewWorkExternalIDConverter(org.orcid.core.adapter.impl.jsonidentifiers.PeerReviewWorkExternalIDConverter) PeerReviewSummary(org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) WorkExternalIDsConverter(org.orcid.core.adapter.impl.jsonidentifiers.WorkExternalIDsConverter) ConverterFactory(ma.glasnost.orika.converter.ConverterFactory) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview)

Example 3 with PeerReviewEntity

use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.

the class JpaJaxbPeerReviewAdapterTest method testToOrgAffiliationRelationEntity.

@Test
public void testToOrgAffiliationRelationEntity() throws JAXBException {
    PeerReview e = getPeerReview(true);
    assertNotNull(e);
    PeerReviewEntity pe = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(e);
    assertNotNull(pe);
    //General info
    assertEquals(Long.valueOf(12345), pe.getId());
    assertEquals(Visibility.PRIVATE.value(), pe.getVisibility().value());
    assertEquals("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"work:external-identifier-id\"}}]}", pe.getExternalIdentifiersJson());
    assertEquals("reviewer", pe.getRole().value());
    assertEquals("review", pe.getType().value());
    assertEquals("peer-review:url", pe.getUrl());
    //Dates
    assertEquals(Integer.valueOf(2), pe.getCompletionDate().getDay());
    assertEquals(Integer.valueOf(2), pe.getCompletionDate().getMonth());
    assertEquals(Integer.valueOf(1848), pe.getCompletionDate().getYear());
    // Source
    assertNull(pe.getSourceId());
    assertNull(pe.getClientSourceId());
    assertNull(pe.getElementSourceId());
    //Check org values
    assertEquals("common:name", pe.getOrg().getName());
    assertEquals("common:city", pe.getOrg().getCity());
    assertEquals("common:region", pe.getOrg().getRegion());
    assertEquals(Iso3166Country.AF.value(), pe.getOrg().getCountry().value());
    assertEquals("common:disambiguated-organization-identifier", pe.getOrg().getOrgDisambiguated().getSourceId());
    assertEquals("common:disambiguation-source", pe.getOrg().getOrgDisambiguated().getSourceType());
    //Check subject        
    assertEquals("{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"DOI\",\"workExternalIdentifierId\":{\"content\":\"peer-review:subject-external-identifier-id\"}}", pe.getSubjectExternalIdentifiersJson());
    assertEquals("peer-review:subject-container-name", pe.getSubjectContainerName());
    assertEquals("peer-review:subject-name", pe.getSubjectName());
    assertEquals("peer-review:subject-translated-name", pe.getSubjectTranslatedName());
    assertEquals("en", pe.getSubjectTranslatedNameLanguageCode());
    assertEquals("peer-review:subject-url", pe.getSubjectUrl());
    assertEquals(WorkType.JOURNAL_ARTICLE, pe.getSubjectType());
    //Check group id
    assertEquals("orcid-generated:12345", pe.getGroupId());
}
Also used : PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 4 with PeerReviewEntity

use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.

the class PeerReviewManagerImpl method createPeerReview.

@Override
public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // If request comes from the API, perform the validations
    if (isApiRequest) {
        // Validate it have at least one ext id
        activityValidator.validatePeerReview(peerReview, sourceEntity, true, isApiRequest, null);
        List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
        // duplicates
        if (!sourceEntity.getSourceId().equals(orcid)) {
            if (peerReviews != null) {
                for (PeerReviewEntity entity : peerReviews) {
                    PeerReview existing = jpaJaxbPeerReviewAdapter.toPeerReview(entity);
                    activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
                }
            }
        } else {
            //check vocab of external identifiers
            externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
            externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
        }
        validateGroupId(peerReview);
    }
    PeerReviewEntity entity = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview);
    // Updates the give organization with the latest organization from
    // database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
    entity.setOrg(updatedOrganization);
    //Set the source
    if (sourceEntity.getSourceProfile() != null) {
        entity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        entity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    entity.setProfile(profile);
    setIncomingPrivacy(entity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(entity, isApiRequest);
    peerReviewDao.persist(entity);
    peerReviewDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(entity));
    return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 5 with PeerReviewEntity

use of org.orcid.persistence.jpa.entities.PeerReviewEntity in project ORCID-Source by ORCID.

the class PeerReviewManagerImpl method updatePeerReview.

@Override
public PeerReview updatePeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
    PeerReviewEntity existingEntity = peerReviewDao.getPeerReview(orcid, peerReview.getPutCode());
    Visibility originalVisibility = existingEntity.getVisibility();
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    //Save the original source
    String existingSourceId = existingEntity.getSourceId();
    String existingClientSourceId = existingEntity.getClientSourceId();
    // If request comes from the API perform validations
    if (isApiRequest) {
        activityValidator.validatePeerReview(peerReview, sourceEntity, false, isApiRequest, originalVisibility);
        validateGroupId(peerReview);
        List<PeerReview> existingReviews = this.findPeerReviews(orcid, System.currentTimeMillis());
        for (PeerReview existing : existingReviews) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(peerReview.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceManager.retrieveSourceEntity());
            }
        }
    } else {
        //check vocab of external identifiers
        externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    PeerReviewEntity updatedEntity = new PeerReviewEntity();
    orcidSecurityManager.checkSource(existingEntity);
    jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview, updatedEntity);
    updatedEntity.setProfile(new ProfileEntity(orcid));
    updatedEntity.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
    updatedEntity.setOrg(updatedOrganization);
    updatedEntity = peerReviewDao.merge(updatedEntity);
    peerReviewDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(updatedEntity));
    return jpaJaxbPeerReviewAdapter.toPeerReview(updatedEntity);
}
Also used : PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)13 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)8 Test (org.junit.Test)6 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)6 BaseTest (org.orcid.core.BaseTest)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 PeerReviewSummary (org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary)2 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 ConverterFactory (ma.glasnost.orika.converter.ConverterFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 PeerReviewWorkExternalIDConverter (org.orcid.core.adapter.impl.jsonidentifiers.PeerReviewWorkExternalIDConverter)1 WorkExternalIDsConverter (org.orcid.core.adapter.impl.jsonidentifiers.WorkExternalIDsConverter)1 ApplicationException (org.orcid.core.exception.ApplicationException)1 CreditName (org.orcid.jaxb.model.common_v2.CreditName)1 Visibility (org.orcid.jaxb.model.common_v2.Visibility)1 Item (org.orcid.jaxb.model.notification.permission_v2.Item)1