use of org.orcid.jaxb.model.message.Activity in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method checkUserCanHoldMoreElement.
private void checkUserCanHoldMoreElement(ActivitiesContainer existingActivities, ActivitiesContainer updatedActivities) {
long activitiesCount = 0;
if (existingActivities != null) {
if (existingActivities.retrieveActivities() != null) {
activitiesCount = existingActivities.retrieveActivities().size();
}
}
if (activitiesCount > maxNumOfActivities) {
throw new ExceedMaxNumberOfElementsException();
}
if (updatedActivities != null) {
if (updatedActivities.retrieveActivities() != null) {
Collection<? extends Activity> elements = updatedActivities.retrieveActivities();
Iterator<? extends Activity> elementsIt = elements.iterator();
if (elementsIt != null) {
while (elementsIt.hasNext()) {
Activity activity = elementsIt.next();
if (activity != null && PojoUtil.isEmpty(activity.getPutCode())) {
activitiesCount += 1;
if (activitiesCount > maxNumOfActivities) {
throw new ExceedMaxNumberOfElementsException();
}
}
}
}
}
}
}
use of org.orcid.jaxb.model.message.Activity in project ORCID-Source by ORCID.
the class OrcidJaxbCopyManagerImpl method copyActivitiesToExistingPreservingVisibility.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void copyActivitiesToExistingPreservingVisibility(ActivitiesContainer existingActivities, ActivitiesContainer updatedActivities, Visibility defaultVisibility) {
if (updatedActivities == null) {
return;
}
if (existingActivities == null) {
try {
existingActivities = updatedActivities.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
Map<String, ? extends Activity> updatedActivitiesMap = updatedActivities.retrieveActivitiesAsMap();
Source targetSource = createSource(sourceManager.retrieveSourceOrcid());
for (Iterator<? extends Activity> existingActivitiesIterator = existingActivities.retrieveActivities().iterator(); existingActivitiesIterator.hasNext(); ) {
Activity existingActivity = existingActivitiesIterator.next();
Activity updatedActivity = updatedActivitiesMap.get(existingActivity.getPutCode());
if (updatedActivity == null) {
if (!(Visibility.PRIVATE.equals(existingActivity.getVisibility()) || isFromDifferentSource(existingActivity))) {
// Remove existing activities unless they are private (we
// need to keep those because the API user won't even know
// they are there) or they are from another source
existingActivitiesIterator.remove();
}
} else {
// Check the source of the existing activity is the same as
// the current source
checkSource(existingActivity);
if (updatedActivity.getVisibility() == null || !updatedActivity.getVisibility().equals(existingActivity.getVisibility())) {
// Keep the visibility from the existing activity unless
// was set by API user
updatedActivity.setVisibility(existingActivity.getVisibility());
}
addSourceToActivity(updatedActivity, targetSource);
// Can remove existing object because will be replaced by
// incoming
existingActivitiesIterator.remove();
}
}
for (Activity updatedActivity : updatedActivities.retrieveActivities()) {
// Set default visibility for any remaining incoming affiliations
if (updatedActivity.getVisibility() == null) {
updatedActivity.setVisibility(defaultVisibility);
}
if (updatedActivity.getPutCode() == null) {
// Check source is correct for any newly added activities, if
// mentioned
addSourceToActivity(updatedActivity, targetSource);
}
}
existingActivities.retrieveActivities().addAll((List) updatedActivities.retrieveActivities());
}
use of org.orcid.jaxb.model.message.Activity in project ORCID-Source by ORCID.
the class OrcidMessageVersionConverterImplV1_2_rc4ToV1_2_rc5 method downgradeProfile.
private void downgradeProfile(OrcidProfile orcidProfile) {
if (orcidProfile != null) {
if (orcidProfile.getOrcidBio() != null)
if (orcidProfile.getOrcidBio().getExternalIdentifiers() != null)
for (ExternalIdentifier externalIdentifier : orcidProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
externalIdentifier.setExternalIdOrcid(externalIdentifier.getExternalIdSource());
externalIdentifier.setExternalIdSource(null);
}
if (orcidProfile.getOrcidActivities() != null) {
if (orcidProfile.getOrcidActivities().getAffiliations() != null)
for (Activity act : orcidProfile.getOrcidActivities().getAffiliations().getAffiliation()) downGradeActivity(act);
if (orcidProfile.getOrcidActivities().getFundings() != null)
for (Activity act : orcidProfile.getOrcidActivities().getFundings().getFundings()) downGradeActivity(act);
if (orcidProfile.getOrcidActivities().getOrcidWorks() != null)
for (Activity act : orcidProfile.getOrcidActivities().getOrcidWorks().getOrcidWork()) downGradeActivity(act);
}
if (orcidProfile.getOrcidInternal() != null) {
orcidProfile.getOrcidInternal().setSalesforceId(null);
}
}
}
Aggregations