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);
}
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);
}
}
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());
}
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);
}
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);
}
Aggregations