Search in sources :

Example 1 with SourceEntity

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

the class NotificationManagerImpl method createNotification.

@Override
public Notification createNotification(String orcid, Notification notification) {
    if (notification.getPutCode() != null) {
        throw new IllegalArgumentException("Put code must be null when creating a new notification");
    }
    NotificationEntity notificationEntity = notificationAdapter.toNotificationEntity(notification);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    if (profile == null) {
        throw OrcidNotFoundException.newInstance(orcid);
    }
    notificationEntity.setProfile(profile);
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    if (sourceEntity != null) {
        // Set source id
        if (sourceEntity.getSourceProfile() != null) {
            notificationEntity.setSourceId(sourceEntity.getSourceProfile().getId());
        }
        if (sourceEntity.getSourceClient() != null) {
            notificationEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
        }
    } else {
        // If we can't find source id, set the user as the source
        notificationEntity.setSourceId(orcid);
    }
    notificationDao.persist(notificationEntity);
    return notificationAdapter.toNotification(notificationEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 2 with SourceEntity

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

the class ActivityValidator method validatePeerReview.

public void validatePeerReview(PeerReview peerReview, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    if (peerReview.getExternalIdentifiers() == null || peerReview.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
        throw new ActivityIdentifierValidationException();
    }
    if (peerReview.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("clientName", sourceEntity.getSourceName());
        throw new InvalidPutCodeException(params);
    }
    if (peerReview.getType() == null) {
        Map<String, String> params = new HashMap<String, String>();
        String peerReviewTypes = Arrays.stream(PeerReviewType.values()).map(element -> element.value()).collect(Collectors.joining(", "));
        params.put("type", "peer review type");
        params.put("values", peerReviewTypes);
        throw new ActivityTypeValidationException();
    }
    externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
    if (peerReview.getSubjectExternalIdentifier() != null) {
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = peerReview.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
}
Also used : FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Arrays(java.util.Arrays) Year(org.orcid.jaxb.model.common_v2.Year) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) OrcidStringUtils(org.orcid.utils.OrcidStringUtils) ActivityTitleValidationException(org.orcid.core.exception.ActivityTitleValidationException) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) Contributor(org.orcid.jaxb.model.common_v2.Contributor) ContributorOrcid(org.orcid.jaxb.model.common_v2.ContributorOrcid) Amount(org.orcid.jaxb.model.common_v2.Amount) PojoUtil(org.orcid.pojo.ajaxForm.PojoUtil) HashMap(java.util.HashMap) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) StringUtils(org.apache.commons.lang3.StringUtils) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Day(org.orcid.jaxb.model.common_v2.Day) Matcher(java.util.regex.Matcher) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Source(org.orcid.jaxb.model.common_v2.Source) Map(java.util.Map) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) CitationType(org.orcid.jaxb.model.record_v2.CitationType) Employment(org.orcid.jaxb.model.record_v2.Employment) Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PublicationDate(org.orcid.jaxb.model.common_v2.PublicationDate) Resource(javax.annotation.Resource) Month(org.orcid.jaxb.model.common_v2.Month) Collectors(java.util.stream.Collectors) WorkContributors(org.orcid.jaxb.model.record_v2.WorkContributors) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) WorkType(org.orcid.jaxb.model.record_v2.WorkType) Iso3166Country(org.orcid.jaxb.model.common_v2.Iso3166Country) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Relationship(org.orcid.jaxb.model.record_v2.Relationship) Work(org.orcid.jaxb.model.record_v2.Work) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Pattern(java.util.regex.Pattern) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) SiteConstants(org.orcid.persistence.constants.SiteConstants) Education(org.orcid.jaxb.model.record_v2.Education) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) PeerReviewType(org.orcid.jaxb.model.record_v2.PeerReviewType) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException)

Example 3 with SourceEntity

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

the class SourceInActivitiesTest method sourceDoesntChange_Affiliation_Test.

@Test
public void sourceDoesntChange_Affiliation_Test() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Education education1 = getEducation(userOrcid);
    assertNotNull(education1);
    assertEquals(userOrcid, education1.retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Education education2 = getEducation(userOrcid);
    assertNotNull(education2);
    assertEquals(CLIENT_1_ID, education2.retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    Education education3 = getEducation(userOrcid);
    assertNotNull(education3);
    assertEquals(CLIENT_2_ID, education3.retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Education education4 = getEducation(userOrcid);
    assertNotNull(education4);
    assertEquals(userOrcid, education4.retrieveSourcePath());
    Education fromDb1 = affiliationsManager.getEducationAffiliation(userOrcid, education1.getPutCode());
    assertNotNull(fromDb1);
    assertEquals(userOrcid, fromDb1.retrieveSourcePath());
    Education fromDb2 = affiliationsManager.getEducationAffiliation(userOrcid, education2.getPutCode());
    assertNotNull(fromDb2);
    assertEquals(CLIENT_1_ID, fromDb2.retrieveSourcePath());
    Education fromDb3 = affiliationsManager.getEducationAffiliation(userOrcid, education3.getPutCode());
    assertNotNull(fromDb3);
    assertEquals(CLIENT_2_ID, fromDb3.retrieveSourcePath());
    Education fromDb4 = affiliationsManager.getEducationAffiliation(userOrcid, education4.getPutCode());
    assertNotNull(fromDb4);
    assertEquals(userOrcid, fromDb4.retrieveSourcePath());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Education(org.orcid.jaxb.model.record_v2.Education) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Example 4 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity 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 5 with SourceEntity

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

the class IdentifierTypeManagerImpl method updateIdentifierType.

@Override
@CacheEvict(value = { "identifier-types", "identifier-types-map" }, allEntries = true)
public IdentifierType updateIdentifierType(IdentifierType id) {
    IdentifierTypeEntity entity = idTypeDao.getEntityByName(externalIdentifierTypeConverter.convertTo(id.getName(), null));
    SourceEntity sourceEntity = new SourceEntity();
    sourceEntity.setSourceClient(entity.getSourceClient());
    securityManager.checkSource(entity);
    entity.setIsDeprecated(id.getDeprecated());
    entity.setResolutionPrefix(id.getResolutionPrefix());
    entity.setValidationRegex(id.getValidationRegex());
    entity.setLastModified(new Date());
    entity.setIsCaseSensitive(id.getCaseSensitive());
    entity.setPrimaryUse(id.getPrimaryUse());
    entity = idTypeDao.updateIdentifierType(entity);
    return adapter.fromEntity(entity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Aggregations

SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)111 Test (org.junit.Test)58 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)57 BaseTest (org.orcid.core.BaseTest)44 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)28 Date (java.util.Date)19 HashMap (java.util.HashMap)15 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)14 Work (org.orcid.jaxb.model.record_v2.Work)14 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)13 Visibility (org.orcid.jaxb.model.common_v2.Visibility)12 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Funding (org.orcid.jaxb.model.record_v2.Funding)10 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)6 WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)6 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)5