use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validateGroupId_invalidGroupIdTest.
@Test(expected = OrcidValidationException.class)
public void validateGroupId_invalidGroupIdTest() {
SourceEntity source = mock(SourceEntity.class);
when(source.getSourceName()).thenReturn("source name");
GroupIdRecord g = getGroupIdRecord();
g.setGroupId("invalid");
activityValidator.validateGroupIdRecord(g, true, source);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validatePeerReview_invalidPutCodeTest.
@Test(expected = InvalidPutCodeException.class)
public void validatePeerReview_invalidPutCodeTest() {
SourceEntity source = mock(SourceEntity.class);
when(source.getSourceName()).thenReturn("source name");
PeerReview pr = getPeerReview();
pr.setPutCode(1L);
activityValidator.validatePeerReview(pr, source, true, true, Visibility.PUBLIC);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method createExternalIdentifier.
@Override
public PersonExternalIdentifier createExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Validate external identifier
PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, true, isApiRequest, null, requireRelationshipOnExternalIdentifier);
// Validate it is not duplicated
List<ExternalIdentifierEntity> existingExternalIdentifiers = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
for (ExternalIdentifierEntity existing : existingExternalIdentifiers) {
if (isDuplicated(existing, externalIdentifier, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "external-identifier");
params.put("value", externalIdentifier.getUrl().getValue());
throw new OrcidDuplicatedElementException(params);
}
}
ExternalIdentifierEntity newEntity = jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
newEntity.setOwner(profile);
newEntity.setDateCreated(new Date());
if (sourceEntity.getSourceProfile() != null) {
newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingPrivacy(newEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
externalIdentifierDao.persist(newEntity);
return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(newEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method createEmploymentAffiliation.
/**
* Add a new employment to the given user
*
* @param orcid
* The user to add the employment
* @param employment
* The employment to add
* @return the added employment
* */
@Override
public Employment createEmploymentAffiliation(String orcid, Employment employment, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateEmployment(employment, sourceEntity, true, isApiRequest, null);
OrgAffiliationRelationEntity employmentEntity = jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity(employment);
// Updates the give organization with the latest organization from
// database
OrgEntity updatedOrganization = orgManager.getOrgEntity(employment);
employmentEntity.setOrg(updatedOrganization);
// Set source id
if (sourceEntity.getSourceProfile() != null) {
employmentEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
employmentEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
employmentEntity.setProfile(profile);
setIncomingWorkPrivacy(employmentEntity, profile);
employmentEntity.setAffiliationType(AffiliationType.EMPLOYMENT);
orgAffiliationRelationDao.persist(employmentEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItem(employmentEntity));
return jpaJaxbEmploymentAdapter.toEmployment(employmentEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method createEducationAffiliation.
/**
* Add a new education to the given user
*
* @param orcid
* The user to add the education
* @param education
* The education to add
* @return the added education
* */
@Override
public Education createEducationAffiliation(String orcid, Education education, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateEducation(education, sourceEntity, true, isApiRequest, null);
OrgAffiliationRelationEntity educationEntity = jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity(education);
// Updates the give organization with the latest organization from
// database
OrgEntity updatedOrganization = orgManager.getOrgEntity(education);
educationEntity.setOrg(updatedOrganization);
// Set source id
if (sourceEntity.getSourceProfile() != null) {
educationEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
educationEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
educationEntity.setProfile(profile);
setIncomingWorkPrivacy(educationEntity, profile);
educationEntity.setAffiliationType(AffiliationType.EDUCATION);
orgAffiliationRelationDao.persist(educationEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItem(educationEntity));
return jpaJaxbEducationAdapter.toEducation(educationEntity);
}
Aggregations