use of org.orcid.jaxb.model.common_v2.Visibility in project ORCID-Source by ORCID.
the class ProfileKeywordManagerImpl method updateKeyword.
@Override
@Transactional
public Keyword updateKeyword(String orcid, Long putCode, Keyword keyword, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileKeywordEntity updatedEntity = profileKeywordDao.getProfileKeyword(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
//Save the original source
String existingSourceId = updatedEntity.getSourceId();
String existingClientSourceId = updatedEntity.getClientSourceId();
// Validate the keyword
PersonValidator.validateKeyword(keyword, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
for (ProfileKeywordEntity existing : existingKeywords) {
if (isDuplicated(existing, keyword, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "keyword");
params.put("value", keyword.getContent());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedEntity);
adapter.toProfileKeywordEntity(keyword, updatedEntity);
updatedEntity.setLastModified(new Date());
//Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
profileKeywordDao.merge(updatedEntity);
return adapter.toKeyword(updatedEntity);
}
use of org.orcid.jaxb.model.common_v2.Visibility in project ORCID-Source by ORCID.
the class ProfileFundingManagerImpl method setIncomingWorkPrivacy.
private void setIncomingWorkPrivacy(ProfileFundingEntity profileFundingEntity, ProfileEntity profile) {
Visibility incomingWorkVisibility = profileFundingEntity.getVisibility();
Visibility defaultWorkVisibility = profile.getActivitiesVisibilityDefault();
if (profile.getClaimed()) {
profileFundingEntity.setVisibility(defaultWorkVisibility);
} else if (incomingWorkVisibility == null) {
profileFundingEntity.setVisibility(Visibility.PRIVATE);
}
}
use of org.orcid.jaxb.model.common_v2.Visibility in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method checkAndFilter.
/**
* Check the permissions of a request over an element. Private
* implementation that will also include a parameter that indicates if we
* should check the token or, if it was already checked previously
*
* @param orcid
* The user owner of the element
* @param element
* The element to check
* @param requiredScope
* The required scope to access this element
* @param tokenAlreadyChecked
* Indicates if the token was already checked previously, so, we
* don't expend time checking it again
* @throws OrcidUnauthorizedException
* In case the token used was not issued for the owner of the
* element
* @throws OrcidAccessControlException
* In case the request doesn't have the required scopes
* @throws OrcidVisibilityException
* In case the element is not visible due the visibility
*/
private void checkAndFilter(String orcid, VisibilityType element, ScopePathType requiredScope, boolean tokenAlreadyChecked) {
if (element == null) {
return;
}
// Check the token was issued for this user
if (!tokenAlreadyChecked) {
isMyToken(orcid);
}
// Check if the client is the source of the element
if (element instanceof Filterable) {
Filterable filterable = (Filterable) element;
OAuth2Authentication oAuth2Authentication = getOAuth2Authentication();
if (oAuth2Authentication != null) {
OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request();
String clientId = authorizationRequest.getClientId();
if (clientId.equals(filterable.retrieveSourcePath())) {
// The client doing the request is the source of the element
return;
}
}
}
// /read-public scope
if (Visibility.PUBLIC.equals(element.getVisibility())) {
try {
checkScopes(ScopePathType.READ_PUBLIC);
// can return it
return;
} catch (OrcidAccessControlException e) {
// Just continue filtering
}
}
// Filter
filter(element, requiredScope);
}
use of org.orcid.jaxb.model.common_v2.Visibility in project ORCID-Source by ORCID.
the class ExternalIdentifierForm method toPersonExternalIdentifier.
public PersonExternalIdentifier toPersonExternalIdentifier() {
PersonExternalIdentifier result = new PersonExternalIdentifier();
if (putCode != null) {
result.setPutCode(Long.valueOf(putCode));
}
result.setDisplayIndex(displayIndex);
if (visibility != null && visibility.getVisibility() != null) {
result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(visibility.getVisibility().value()));
}
if (url != null) {
result.setUrl(new Url(url));
}
result.setType(commonName);
result.setValue(reference);
return result;
}
use of org.orcid.jaxb.model.common_v2.Visibility in project ORCID-Source by ORCID.
the class ProfileFundingManagerTest method getFundingSummary.
private FundingSummary getFundingSummary(String titleValue, String extIdValue, Visibility visibility) {
FundingSummary summary = new FundingSummary();
FundingTitle fundingTitle = new FundingTitle();
fundingTitle.setTitle(new Title(titleValue));
summary.setTitle(fundingTitle);
summary.setVisibility(visibility);
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://orcid.org"));
extId.setValue(extIdValue);
extIds.getExternalIdentifier().add(extId);
summary.setExternalIdentifiers(extIds);
Organization org = new Organization();
org.setName("org-name");
OrganizationAddress address = new OrganizationAddress();
address.setCity("city");
address.setCountry(Iso3166Country.US);
org.setAddress(address);
summary.setOrganization(org);
return summary;
}
Aggregations