use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class MigrateNamesAndBioToTheirOwnTables method migrateData.
private void migrateData() {
LOG.debug("Starting migration process");
List<Object[]> profileElements = Collections.emptyList();
int counter = 0;
int batchCount = 0;
do {
LOG.debug("About to fetch a batch from DB");
profileElements = profileDao.findProfilesWhereNamesAreNotMigrated(batchSize);
LOG.debug("Procesing batch, profiles processed so far: " + counter);
for (final Object[] profileElement : profileElements) {
String orcid = (String) profileElement[0];
String givenNames = (String) profileElement[1];
String familyName = (String) profileElement[2];
String creditName = (String) profileElement[3];
String namesVisibility = (String) profileElement[4];
String biography = (String) profileElement[5];
String biographyVisibility = (String) profileElement[6];
String defaultVisibility = (String) profileElement[7];
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
LOG.info("Migrating names for profile: {}", orcid);
if (!recordNameDao.exists(orcid)) {
ProfileEntity profile = new ProfileEntity(orcid);
RecordNameEntity recordName = new RecordNameEntity();
recordName.setProfile(profile);
recordName.setCreditName(creditName);
recordName.setFamilyName(familyName);
recordName.setGivenNames(givenNames);
if (PojoUtil.isEmpty(namesVisibility)) {
recordName.setVisibility(Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value()));
} else {
recordName.setVisibility(Visibility.fromValue(namesVisibility));
}
recordNameDao.createRecordName(recordName);
}
LOG.info("Migrating biography for profile: {}", orcid);
if (!biographyDao.exists(orcid)) {
Visibility visibility = Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value());
if (!PojoUtil.isEmpty(biographyVisibility)) {
visibility = Visibility.fromValue(biographyVisibility);
} else if (!PojoUtil.isEmpty(defaultVisibility)) {
visibility = Visibility.fromValue(defaultVisibility);
}
biographyDao.persistBiography(orcid, biography, visibility);
}
}
});
counter += 1;
}
batchCount += 1;
LOG.info("Batches processed so far: {}", String.valueOf(batchCount));
// Stop if we ran the number of batches
if (numberOfBatches > 0) {
if (batchCount >= numberOfBatches) {
profileElements = null;
}
}
} while (profileElements != null && !profileElements.isEmpty());
LOG.debug("Finished migration process");
}
use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class ResearcherUrlManagerImpl method updateResearcherUrl.
@Override
@Transactional
public ResearcherUrl updateResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
ResearcherUrlEntity updatedResearcherUrlEntity = researcherUrlDao.getResearcherUrl(orcid, researcherUrl.getPutCode());
Visibility originalVisibility = Visibility.fromValue(updatedResearcherUrlEntity.getVisibility().value());
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = updatedResearcherUrlEntity.getSourceId();
String existingClientSourceId = updatedResearcherUrlEntity.getClientSourceId();
// Validate the researcher url
PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
for (ResearcherUrlEntity existing : existingResearcherUrls) {
if (isDuplicated(existing, researcherUrl, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "researcher-url");
params.put("value", researcherUrl.getUrlName());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedResearcherUrlEntity);
jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl, updatedResearcherUrlEntity);
updatedResearcherUrlEntity.setLastModified(new Date());
// Be sure it doesn't overwrite the source
updatedResearcherUrlEntity.setSourceId(existingSourceId);
updatedResearcherUrlEntity.setClientSourceId(existingClientSourceId);
researcherUrlDao.merge(updatedResearcherUrlEntity);
return jpaJaxbResearcherUrlAdapter.toResearcherUrl(updatedResearcherUrlEntity);
}
use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method updateExternalIdentifier.
@Override
public PersonExternalIdentifier updateExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ExternalIdentifierEntity updatedExternalIdentifierEntity = externalIdentifierDao.getExternalIdentifierEntity(orcid, externalIdentifier.getPutCode());
// Save the original source
String existingSourceId = updatedExternalIdentifierEntity.getSourceId();
String existingClientSourceId = updatedExternalIdentifierEntity.getClientSourceId();
Visibility originalVisibility = Visibility.fromValue(updatedExternalIdentifierEntity.getVisibility().value());
// Validate external identifier
PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, false, isApiRequest, originalVisibility, 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);
}
}
orcidSecurityManager.checkSource(updatedExternalIdentifierEntity);
jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier, updatedExternalIdentifierEntity);
updatedExternalIdentifierEntity.setLastModified(new Date());
// Set source
updatedExternalIdentifierEntity.setSourceId(existingSourceId);
updatedExternalIdentifierEntity.setClientSourceId(existingClientSourceId);
externalIdentifierDao.merge(updatedExternalIdentifierEntity);
return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(updatedExternalIdentifierEntity);
}
use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class OtherNameManagerImpl method updateOtherName.
@Override
@Transactional
public OtherName updateOtherName(String orcid, Long putCode, OtherName otherName, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
OtherNameEntity updatedOtherNameEntity = otherNameDao.getOtherName(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedOtherNameEntity.getVisibility().value());
// Save the original source
String existingSourceId = updatedOtherNameEntity.getSourceId();
String existingClientSourceId = updatedOtherNameEntity.getClientSourceId();
// Validate the other name
PersonValidator.validateOtherName(otherName, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
for (OtherNameEntity existing : existingOtherNames) {
if (isDuplicated(existing, otherName, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "otherName");
params.put("value", otherName.getContent());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedOtherNameEntity);
jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName, updatedOtherNameEntity);
updatedOtherNameEntity.setLastModified(new Date());
// Be sure it doesn't overwrite the source
updatedOtherNameEntity.setSourceId(existingSourceId);
updatedOtherNameEntity.setClientSourceId(existingClientSourceId);
otherNameDao.merge(updatedOtherNameEntity);
return jpaJaxbOtherNameAdapter.toOtherName(updatedOtherNameEntity);
}
use of org.orcid.jaxb.model.common_rc1.Visibility 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);
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, createItemList(updatedEntity));
return jpaJaxbPeerReviewAdapter.toPeerReview(updatedEntity);
}
Aggregations