use of org.orcid.jaxb.model.v3.dev1.record.Funding in project ORCID-Source by ORCID.
the class JSONFundingExternalIdentifiersConverterV3Test method testConvertTo.
@Test
public void testConvertTo() throws JAXBException {
Funding funding = getFunding();
assertEquals("{\"fundingExternalIdentifier\":[{\"type\":\"GRANT_NUMBER\",\"value\":\"funding:external-identifier-value\",\"url\":{\"value\":\"http://tempuri.org\"},\"relationship\":\"SELF\"},{\"type\":\"GRANT_NUMBER\",\"value\":\"funding:external-identifier-value2\",\"url\":{\"value\":\"http://tempuri.org/2\"},\"relationship\":\"SELF\"}]}", converter.convertTo(funding.getExternalIdentifiers(), null));
}
use of org.orcid.jaxb.model.v3.dev1.record.Funding in project ORCID-Source by ORCID.
the class JSONFundingExternalIdentifiersConverterV3Test method getFunding.
private Funding getFunding() throws JAXBException {
JAXBContext context = JAXBContext.newInstance(new Class[] { Funding.class });
Unmarshaller unmarshaller = context.createUnmarshaller();
String name = "/record_3.0_dev1/samples/read_samples/funding-full-3.0_dev1.xml";
InputStream inputStream = getClass().getResourceAsStream(name);
return (Funding) unmarshaller.unmarshal(inputStream);
}
use of org.orcid.jaxb.model.v3.dev1.record.Funding in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method checkAndFilter.
@Override
public void checkAndFilter(String orcid, ActivitiesSummary activities) {
if (activities == null) {
return;
}
// Check the token
isMyToken(orcid);
// Distinctions
if (activities.getDistinctions() != null) {
checkAndFilter(orcid, activities.getDistinctions().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
}
// Educations
if (activities.getEducations() != null) {
checkAndFilter(orcid, activities.getEducations().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
}
// Employments
if (activities.getEmployments() != null) {
checkAndFilter(orcid, activities.getEmployments().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
}
// Invited positions
if (activities.getInvitedPositions() != null) {
checkAndFilter(orcid, activities.getInvitedPositions().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
}
// Memberships
if (activities.getMemberships() != null) {
checkAndFilter(orcid, activities.getMemberships().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
}
// Qualifications
if (activities.getQualifications() != null) {
checkAndFilter(orcid, activities.getQualifications().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
}
// Services
if (activities.getServices() != null) {
checkAndFilter(orcid, activities.getServices().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
}
// Funding
if (activities.getFundings() != null) {
Iterator<FundingGroup> groupIt = activities.getFundings().getFundingGroup().iterator();
while (groupIt.hasNext()) {
FundingGroup group = groupIt.next();
// Filter the list of elements
checkAndFilter(orcid, group.getFundingSummary(), READ_FUNDING_REQUIRED_SCOPE, true);
// Clean external identifiers
if (group.getFundingSummary().isEmpty()) {
groupIt.remove();
} else {
filterExternalIdentifiers(group);
}
}
}
// PeerReviews
if (activities.getPeerReviews() != null) {
Iterator<PeerReviewGroup> groupIt = activities.getPeerReviews().getPeerReviewGroup().iterator();
while (groupIt.hasNext()) {
PeerReviewGroup group = groupIt.next();
// Filter the list of elements
checkAndFilter(orcid, group.getPeerReviewSummary(), READ_PEER_REVIEWS_REQUIRED_SCOPE, true);
if (group.getPeerReviewSummary().isEmpty()) {
groupIt.remove();
}
}
}
// Works
if (activities.getWorks() != null) {
Iterator<WorkGroup> groupIt = activities.getWorks().getWorkGroup().iterator();
while (groupIt.hasNext()) {
WorkGroup group = groupIt.next();
// Filter the list of elements
checkAndFilter(orcid, group.getWorkSummary(), READ_WORKS_REQUIRED_SCOPE, true);
// Clean external identifiers
if (group.getWorkSummary().isEmpty()) {
groupIt.remove();
} else {
filterExternalIdentifiers(group);
}
}
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Funding in project ORCID-Source by ORCID.
the class ProfileFundingManagerImpl method updateFunding.
/**
* Updates a funding that belongs to the given user
* @param orcid
* The user
* @param funding
* The funding to update
* @return the updated funding
*/
@Override
public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, funding.getPutCode());
Visibility originalVisibility = Visibility.fromValue(pfe.getVisibility().value());
// Save the original source
String existingSourceId = pfe.getSourceId();
String existingClientSourceId = pfe.getClientSourceId();
activityValidator.validateFunding(funding, sourceEntity, false, isApiRequest, originalVisibility);
if (!isApiRequest) {
List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
for (ProfileFundingEntity existingFunding : existingFundings) {
Funding existing = jpaJaxbFundingAdapter.toFunding(existingFunding);
if (!existing.getPutCode().equals(funding.getPutCode())) {
activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
}
orcidSecurityManager.checkSource(pfe);
jpaJaxbFundingAdapter.toProfileFundingEntity(funding, pfe);
pfe.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(originalVisibility.value()));
// Be sure it doesn't overwrite the source
pfe.setSourceId(existingSourceId);
pfe.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
pfe.setOrg(updatedOrganization);
pfe = profileFundingDao.merge(pfe);
profileFundingDao.flush();
if (!isApiRequest) {
notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe));
}
return jpaJaxbFundingAdapter.toFunding(pfe);
}
use of org.orcid.jaxb.model.v3.dev1.record.Funding in project ORCID-Source by ORCID.
the class ProfileFundingManagerImpl method createFunding.
/**
* Add a new funding to the given user
* @param orcid
* The user to add the funding
* @param funding
* The funding to add
* @return the added funding
*/
@Override
@Transactional
public Funding createFunding(String orcid, Funding funding, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateFunding(funding, sourceEntity, true, isApiRequest, null);
// Check for duplicates
List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
List<Funding> fundings = jpaJaxbFundingAdapter.toFunding(existingFundings);
if (fundings != null && isApiRequest) {
for (Funding exstingFunding : fundings) {
activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), exstingFunding.getExternalIdentifiers(), exstingFunding.getSource(), sourceEntity);
}
}
ProfileFundingEntity profileFundingEntity = jpaJaxbFundingAdapter.toProfileFundingEntity(funding);
// Updates the give organization with the latest organization from database
OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
profileFundingEntity.setOrg(updatedOrganization);
// Set the source
if (sourceEntity.getSourceProfile() != null) {
profileFundingEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
profileFundingEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
profileFundingEntity.setProfile(profile);
setIncomingWorkPrivacy(profileFundingEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(profileFundingEntity, isApiRequest);
profileFundingDao.persist(profileFundingEntity);
profileFundingDao.flush();
if (isApiRequest) {
notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity));
}
return jpaJaxbFundingAdapter.toFunding(profileFundingEntity);
}
Aggregations