use of org.orcid.persistence.jpa.entities.OrgEntity 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, getLastModified(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, createItemList(entity));
return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class OrgDisambiguatedManagerImpl method convertEntityToDocument.
private OrgDisambiguatedSolrDocument convertEntityToDocument(OrgDisambiguatedEntity entity) {
OrgDisambiguatedSolrDocument document = new OrgDisambiguatedSolrDocument();
document.setOrgDisambiguatedId(entity.getId());
document.setOrgDisambiguatedName(entity.getName());
document.setOrgDisambiguatedCity(entity.getCity());
document.setOrgDisambiguatedRegion(entity.getRegion());
if (entity.getCountry() != null)
document.setOrgDisambiguatedCountry(entity.getCountry().value());
document.setOrgDisambiguatedIdFromSource(entity.getSourceId());
document.setOrgDisambiguatedIdSourceType(entity.getSourceType());
document.setOrgDisambiguatedType(entity.getOrgType());
document.setOrgDisambiguatedPopularity(entity.getPopularity());
Set<String> orgNames = new HashSet<>();
orgNames.add(entity.getName());
Set<OrgEntity> orgs = entity.getOrgs();
if (orgs != null) {
for (OrgEntity org : orgs) {
orgNames.add(org.getName());
}
}
document.setOrgNames(new ArrayList<>(orgNames));
if (FUNDING_ORG_TYPE.equals(entity.getSourceType())) {
document.setFundingOrg(true);
} else {
document.setFundingOrg(false);
}
return document;
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class OrgManagerImpl method createUpdate.
@Override
public OrgEntity createUpdate(OrgEntity org) {
OrgEntity existingOrg = orgDao.findByNameCityRegionAndCountry(org.getName(), org.getCity(), org.getRegion(), org.getCountry());
if (existingOrg != null) {
return existingOrg;
}
SourceEntity entity = sourceManager.retrieveSourceEntity();
if (entity != null) {
SourceEntity newEntity = new SourceEntity();
if (entity.getSourceClient() != null) {
newEntity.setSourceClient(new ClientDetailsEntity(entity.getSourceClient().getId()));
}
if (entity.getSourceProfile() != null) {
newEntity.setSourceProfile(new ProfileEntity(entity.getSourceProfile().getId()));
}
org.setSource(newEntity);
}
orgDao.persist(org);
return org;
}
use of org.orcid.persistence.jpa.entities.OrgEntity 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, getLastModified(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, createItemList(entity));
return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}
use of org.orcid.persistence.jpa.entities.OrgEntity 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