use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method updateEmploymentAffiliation.
/**
* Updates a employment that belongs to the given user
*
* @param orcid
* The user
* @param employment
* The employment to update
* @return the updated employment
* */
@Override
public Employment updateEmploymentAffiliation(String orcid, Employment employment, boolean isApiRequest) {
OrgAffiliationRelationEntity employmentEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, employment.getPutCode());
Visibility originalVisibility = employmentEntity.getVisibility();
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
//Save the original source
String existingSourceId = employmentEntity.getSourceId();
String existingClientSourceId = employmentEntity.getClientSourceId();
orcidSecurityManager.checkSource(employmentEntity);
activityValidator.validateEmployment(employment, sourceEntity, false, isApiRequest, originalVisibility);
jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity(employment, employmentEntity);
employmentEntity.setVisibility(originalVisibility);
//Be sure it doesn't overwrite the source
employmentEntity.setSourceId(existingSourceId);
employmentEntity.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from
// database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(employment);
employmentEntity.setOrg(updatedOrganization);
employmentEntity.setAffiliationType(AffiliationType.EMPLOYMENT);
employmentEntity = orgAffiliationRelationDao.merge(employmentEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItem(employmentEntity));
return jpaJaxbEmploymentAdapter.toEmployment(employmentEntity);
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method updateEducationAffiliation.
/**
* Updates a education that belongs to the given user
*
* @param orcid
* The user
* @param education
* The education to update
* @return the updated education
* */
@Override
public Education updateEducationAffiliation(String orcid, Education education, boolean isApiRequest) {
OrgAffiliationRelationEntity educationEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, education.getPutCode());
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
//Save the original source
String existingSourceId = educationEntity.getSourceId();
String existingClientSourceId = educationEntity.getClientSourceId();
Visibility originalVisibility = educationEntity.getVisibility();
orcidSecurityManager.checkSource(educationEntity);
activityValidator.validateEducation(education, sourceEntity, false, isApiRequest, originalVisibility);
jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity(education, educationEntity);
educationEntity.setVisibility(originalVisibility);
//Be sure it doesn't overwrite the source
educationEntity.setSourceId(existingSourceId);
educationEntity.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from
// database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(education);
educationEntity.setOrg(updatedOrganization);
educationEntity.setAffiliationType(AffiliationType.EDUCATION);
educationEntity = orgAffiliationRelationDao.merge(educationEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItem(educationEntity));
return jpaJaxbEducationAdapter.toEducation(educationEntity);
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method checkSourceAndDelete.
/**
* Deletes a given affiliation, if and only if, the client that requested
* the delete is the source of the affiliation
*
* @param orcid
* the affiliation owner
* @param affiliationId
* The affiliation id
* @return true if the affiliation was deleted, false otherwise
* */
@Override
public boolean checkSourceAndDelete(String orcid, Long affiliationId) {
OrgAffiliationRelationEntity affiliationEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, affiliationId);
orcidSecurityManager.checkSource(affiliationEntity);
boolean result = orgAffiliationRelationDao.removeOrgAffiliationRelation(orcid, affiliationId);
if (result)
notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItem(affiliationEntity));
return result;
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerReadOnlyImpl method getAffiliations.
@Override
public List<Affiliation> getAffiliations(String orcid) {
List<OrgAffiliationRelationEntity> affiliations = orgAffiliationRelationDao.getByUser(orcid);
List<Affiliation> result = new ArrayList<Affiliation>();
if (affiliations != null) {
for (OrgAffiliationRelationEntity affiliation : affiliations) {
if (AffiliationType.EDUCATION.equals(affiliation.getAffiliationType())) {
result.add(jpaJaxbEducationAdapter.toEducation(affiliation));
} else {
result.add(jpaJaxbEmploymentAdapter.toEmployment(affiliation));
}
}
}
return result;
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity 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();
} else {
orgRelationEntity = exisitingOrgAffiliationEntity;
orgRelationEntity.clean();
}
FuzzyDate startDate = affiliation.getStartDate();
FuzzyDate endDate = affiliation.getEndDate();
if (affiliation.getType() != null) {
orgRelationEntity.setAffiliationType(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);
}
//Set source
setSource(affiliation.getSource(), orgRelationEntity);
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;
}
Aggregations