use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class LoadRinggoldData method generateOrganizations.
private void generateOrganizations(OrgDisambiguatedEntity disambiguatedEntity, List<JsonNode> altNames) {
Date now = new Date();
altNames.forEach(altName -> {
String name = altName.get("name").asText();
LOGGER.info("Processing organization {} for {}", name, disambiguatedEntity.getId());
String city = altName.get("city").asText();
Iso3166Country country = Iso3166Country.fromValue(altName.get("country").asText());
// Not happy with line below. Can steal from other ORG ID types.
OrgEntity existingOrg = orgDao.findByNameCityRegionAndCountry(name, city, null, country);
if (existingOrg != null) {
if (existingOrg.getOrgDisambiguated() == null) {
existingOrg.setOrgDisambiguated(disambiguatedEntity);
existingOrg.setLastModified(now);
orgDao.merge(existingOrg);
numUpdatedOrgs++;
}
} else {
OrgEntity newOrg = new OrgEntity();
newOrg.setDateCreated(now);
newOrg.setLastModified(now);
newOrg.setCity(city);
newOrg.setCountry(country);
newOrg.setName(name);
newOrg.setOrgDisambiguated(disambiguatedEntity);
orgDao.persist(newOrg);
numAddedOrgs++;
}
});
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class JSONPeerReviewWorkExternalIdentifierConverterV2Test method getPeerReviewEntity.
private PeerReviewEntity getPeerReviewEntity() {
OrgEntity orgEntity = new OrgEntity();
orgEntity.setCity("org:city");
orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
orgEntity.setName("org:name");
orgEntity.setRegion("org:region");
orgEntity.setUrl("org:url");
orgEntity.setSource(new SourceEntity("APP-000000001"));
PeerReviewEntity result = new PeerReviewEntity();
result.setOrg(orgEntity);
result.setCompletionDate(new CompletionDateEntity(2015, 1, 1));
result.setExternalIdentifiersJson("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"peer-review:external-identifier-id\"}}]}");
result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
result.setRole(Role.MEMBER);
result.setType(PeerReviewType.EVALUATION);
result.setUrl("peer-review:url");
result.setSubjectExternalIdentifiersJson("{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"peer-review:subject-external-identifier-id\"}}");
result.setSubjectContainerName("peer-review:subject-container-name");
result.setSubjectName("peer-review:subject-name");
result.setSubjectTranslatedName("peer-review:subject-translated-name");
result.setSubjectTranslatedNameLanguageCode("en");
result.setSubjectUrl("peer-review:subject-url");
result.setSubjectType(WorkType.BOOK_REVIEW);
result.setVisibility(Visibility.PRIVATE);
result.setClientSourceId("APP-000000001");
result.setGroupId("orcid-generated:12345");
result.setId(12345L);
return result;
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method getOrgAffiliationRelationEntity.
private OrgAffiliationRelationEntity getOrgAffiliationRelationEntity(Affiliation affiliation, OrgAffiliationRelationEntity exisitingOrgAffiliationEntity) {
if (affiliation != null) {
// Get the org
OrgEntity orgEntity = getOrgEntity(affiliation);
OrgAffiliationRelationEntity orgRelationEntity = null;
if (exisitingOrgAffiliationEntity == null) {
String putCode = affiliation.getPutCode();
if (StringUtils.isNotBlank(putCode) && !"-1".equals(putCode)) {
throw new IllegalArgumentException("Invalid put-code was supplied for an affiliation: " + putCode);
}
orgRelationEntity = new OrgAffiliationRelationEntity();
setSource(sourceManager.retrieveSourceEntity(), orgRelationEntity);
} else {
orgRelationEntity = exisitingOrgAffiliationEntity;
orgRelationEntity.clean();
}
FuzzyDate startDate = affiliation.getStartDate();
FuzzyDate endDate = affiliation.getEndDate();
if (affiliation.getType() != null) {
orgRelationEntity.setAffiliationType(org.orcid.jaxb.model.v3.dev1.record.AffiliationType.fromValue(affiliation.getType().value()));
}
if (affiliation.getVisibility() != null) {
orgRelationEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(affiliation.getVisibility().value()));
} else {
orgRelationEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
}
orgRelationEntity.setDepartment(affiliation.getDepartmentName());
orgRelationEntity.setEndDate(endDate != null ? new EndDateEntity(endDate) : null);
orgRelationEntity.setOrg(orgEntity);
orgRelationEntity.setTitle(affiliation.getRoleTitle());
orgRelationEntity.setStartDate(startDate != null ? new StartDateEntity(startDate) : null);
if (affiliation.getCreatedDate() != null && affiliation.getCreatedDate().getValue() != null)
orgRelationEntity.setDateCreated(affiliation.getCreatedDate().getValue().toGregorianCalendar().getTime());
if (affiliation.getLastModifiedDate() != null && affiliation.getLastModifiedDate().getValue() != null)
orgRelationEntity.setLastModified(affiliation.getLastModifiedDate().getValue().toGregorianCalendar().getTime());
return orgRelationEntity;
}
return null;
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method updateAffiliation.
public Affiliation updateAffiliation(String orcid, Affiliation affiliation, boolean isApiRequest, AffiliationType type) {
OrgAffiliationRelationEntity entity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, affiliation.getPutCode());
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = entity.getSourceId();
String existingClientSourceId = entity.getClientSourceId();
org.orcid.jaxb.model.common_v2.Visibility originalVisibility = entity.getVisibility();
orcidSecurityManager.checkSource(entity);
activityValidator.validateAffiliation(affiliation, sourceEntity, false, isApiRequest, org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(originalVisibility.value()));
if (isApiRequest) {
checkAffiliationExternalIDsForDuplicates(orcid, affiliation, sourceEntity);
}
switch(type) {
case DISTINCTION:
jpaJaxbDistinctionAdapter.toOrgAffiliationRelationEntity((Distinction) affiliation, entity);
break;
case EDUCATION:
jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity((Education) affiliation, entity);
break;
case EMPLOYMENT:
jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity((Employment) affiliation, entity);
break;
case INVITED_POSITION:
jpaJaxbInvitedPositionAdapter.toOrgAffiliationRelationEntity((InvitedPosition) affiliation, entity);
break;
case MEMBERSHIP:
jpaJaxbMembershipAdapter.toOrgAffiliationRelationEntity((Membership) affiliation, entity);
break;
case QUALIFICATION:
jpaJaxbQualificationAdapter.toOrgAffiliationRelationEntity((Qualification) affiliation, entity);
break;
case SERVICE:
jpaJaxbServiceAdapter.toOrgAffiliationRelationEntity((Service) affiliation, entity);
break;
}
entity.setVisibility(originalVisibility);
// Be sure it doesn't overwrite the source
entity.setSourceId(existingSourceId);
entity.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from
// database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(affiliation);
entity.setOrg(updatedOrganization);
entity.setAffiliationType(type);
entity = orgAffiliationRelationDao.merge(entity);
orgAffiliationRelationDao.flush();
Affiliation result = null;
switch(type) {
case DISTINCTION:
notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity));
result = jpaJaxbDistinctionAdapter.toDistinction(entity);
break;
case EDUCATION:
notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity));
result = jpaJaxbEducationAdapter.toEducation(entity);
break;
case EMPLOYMENT:
notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity));
result = jpaJaxbEmploymentAdapter.toEmployment(entity);
break;
case INVITED_POSITION:
notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity));
result = jpaJaxbInvitedPositionAdapter.toInvitedPosition(entity);
break;
case MEMBERSHIP:
notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity));
result = jpaJaxbMembershipAdapter.toMembership(entity);
break;
case QUALIFICATION:
notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity));
result = jpaJaxbQualificationAdapter.toQualification(entity);
break;
case SERVICE:
notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity));
result = jpaJaxbServiceAdapter.toService(entity);
break;
}
return result;
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class OrgManagerImpl method getOrgEntity.
@Override
public OrgEntity getOrgEntity(OrganizationHolder holder) {
if (holder == null)
return null;
OrgEntity orgEntity = new OrgEntity();
org.orcid.jaxb.model.v3.dev1.common.Organization organization = holder.getOrganization();
orgEntity.setName(organization.getName());
org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress address = organization.getAddress();
orgEntity.setCity(address.getCity());
orgEntity.setRegion(address.getRegion());
orgEntity.setCountry(Iso3166Country.fromValue(address.getCountry().value()));
if (organization.getDisambiguatedOrganization() != null && organization.getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier() != null) {
// if disambiguated org is present (must be for v3 API, but not UI) it must be valid
OrgDisambiguatedEntity disambiguatedOrg = orgDisambiguatedDao.findBySourceIdAndSourceType(organization.getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier(), organization.getDisambiguatedOrganization().getDisambiguationSource());
if (disambiguatedOrg == null) {
throw new InvalidDisambiguatedOrgException();
}
orgEntity.setOrgDisambiguated(disambiguatedOrg);
}
return matchOrCreateOrg(orgEntity);
}
Aggregations