use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class WorksController method initializeFields.
private void initializeFields(WorkForm w) {
if (w.getVisibility() == null) {
ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
Visibility v = profile.getActivitiesVisibilityDefault() == null ? Visibility.fromValue(OrcidVisibilityDefaults.WORKS_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault();
w.setVisibility(v);
}
if (w.getTitle() == null) {
w.setTitle(new Text());
}
if (w.getSubtitle() == null) {
w.setSubtitle(new Text());
}
if (w.getTranslatedTitle() == null) {
TranslatedTitleForm tt = new TranslatedTitleForm();
tt.setContent(new String());
tt.setLanguageCode(new String());
tt.setLanguageName(new String());
w.setTranslatedTitle(tt);
}
if (PojoUtil.isEmpty(w.getJournalTitle())) {
Text jt = new Text();
jt.setRequired(false);
w.setJournalTitle(jt);
}
if (PojoUtil.isEmpty(w.getWorkCategory())) {
Text wCategoryText = new Text();
wCategoryText.setValue(new String());
wCategoryText.setRequired(true);
w.setWorkCategory(wCategoryText);
}
if (PojoUtil.isEmpty(w.getWorkType())) {
Text wTypeText = new Text();
wTypeText.setValue(new String());
wTypeText.setRequired(true);
w.setWorkType(wTypeText);
}
initializePublicationDate(w);
if (w.getWorkExternalIdentifiers() == null || w.getWorkExternalIdentifiers().isEmpty()) {
WorkExternalIdentifier wei = new WorkExternalIdentifier();
Text wdiType = new Text();
wdiType.setValue(new String());
wei.setWorkExternalIdentifierId(new Text());
wei.setWorkExternalIdentifierType(wdiType);
wei.setRelationship(Text.valueOf(Relationship.SELF.value()));
List<WorkExternalIdentifier> wdiL = new ArrayList<WorkExternalIdentifier>();
wdiL.add(wei);
w.setWorkExternalIdentifiers(wdiL);
}
if (PojoUtil.isEmpty(w.getUrl())) {
w.setUrl(new Text());
}
if (w.getContributors() == null || w.getContributors().isEmpty()) {
List<Contributor> contrList = new ArrayList<Contributor>();
w.setContributors(contrList);
}
if (PojoUtil.isEmpty(w.getShortDescription())) {
w.setShortDescription(new Text());
}
if (PojoUtil.isEmpty(w.getLanguageCode())) {
Text lc = new Text();
lc.setRequired(false);
w.setLanguageCode(lc);
}
if (PojoUtil.isEmpty(w.getLanguageName())) {
Text ln = new Text();
ln.setRequired(false);
w.setLanguageName(ln);
}
if (PojoUtil.isEmpty(w.getCountryCode())) {
w.setCountryCode(new Text());
}
if (PojoUtil.isEmpty(w.getCountryName())) {
w.setCountryName(new Text());
}
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class AddressManagerImpl method updateAddress.
@Override
@Transactional
public Address updateAddress(String orcid, Long putCode, Address address, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
AddressEntity updatedEntity = addressDao.getAddress(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
//Save the original source
String existingSourceId = updatedEntity.getSourceId();
String existingClientSourceId = updatedEntity.getClientSourceId();
//If it is an update from the API, check the source and preserve the original visibility
if (isApiRequest) {
orcidSecurityManager.checkSource(updatedEntity);
}
// Validate the address
PersonValidator.validateAddress(address, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<AddressEntity> existingAddresses = addressDao.getAddresses(orcid, getLastModified(orcid));
for (AddressEntity existing : existingAddresses) {
//If it is not the same element
if (!existing.getId().equals(address.getPutCode())) {
if (isDuplicated(existing, address, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "address");
params.put("value", address.getCountry().getValue().value());
throw new OrcidDuplicatedElementException(params);
}
}
}
adapter.toAddressEntity(address, updatedEntity);
updatedEntity.setLastModified(new Date());
//Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
addressDao.merge(updatedEntity);
return adapter.toAddress(updatedEntity);
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class AddressManagerImpl method setIncomingPrivacy.
private void setIncomingPrivacy(AddressEntity entity, ProfileEntity profile) {
org.orcid.jaxb.model.common_v2.Visibility incomingCountryVisibility = entity.getVisibility();
org.orcid.jaxb.model.common_v2.Visibility defaultCountryVisibility = (profile.getActivitiesVisibilityDefault() == null) ? org.orcid.jaxb.model.common_v2.Visibility.PRIVATE : org.orcid.jaxb.model.common_v2.Visibility.fromValue(profile.getActivitiesVisibilityDefault().value());
if (profile.getClaimed() != null && profile.getClaimed()) {
entity.setVisibility(defaultCountryVisibility);
} else if (incomingCountryVisibility == null) {
entity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
}
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method setIncomingPrivacy.
private void setIncomingPrivacy(ExternalIdentifierEntity entity, ProfileEntity profile) {
org.orcid.jaxb.model.common_v2.Visibility incomingExternalIdentifierVisibility = entity.getVisibility();
org.orcid.jaxb.model.common_v2.Visibility defaultExternalIdentifierVisibility = (profile.getActivitiesVisibilityDefault() == null) ? org.orcid.jaxb.model.common_v2.Visibility.PRIVATE : org.orcid.jaxb.model.common_v2.Visibility.fromValue(profile.getActivitiesVisibilityDefault().value());
if (profile.getClaimed() != null && profile.getClaimed()) {
entity.setVisibility(defaultExternalIdentifierVisibility);
} else if (incomingExternalIdentifierVisibility == null) {
entity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
}
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method updateExternalIdentifier.
@Override
public PersonExternalIdentifier updateExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ExternalIdentifierEntity updatedExternalIdentifierEntity = externalIdentifierDao.getExternalIdentifierEntity(orcid, externalIdentifier.getPutCode());
//Save the original source
String existingSourceId = updatedExternalIdentifierEntity.getSourceId();
String existingClientSourceId = updatedExternalIdentifierEntity.getClientSourceId();
Visibility originalVisibility = Visibility.fromValue(updatedExternalIdentifierEntity.getVisibility().value());
// Validate external identifier
PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, false, isApiRequest, originalVisibility, requireRelationshipOnExternalIdentifier);
// Validate it is not duplicated
List<ExternalIdentifierEntity> existingExternalIdentifiers = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
for (ExternalIdentifierEntity existing : existingExternalIdentifiers) {
if (isDuplicated(existing, externalIdentifier, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "external-identifier");
params.put("value", externalIdentifier.getUrl().getValue());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedExternalIdentifierEntity);
jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier, updatedExternalIdentifierEntity);
updatedExternalIdentifierEntity.setLastModified(new Date());
//Set source
updatedExternalIdentifierEntity.setSourceId(existingSourceId);
updatedExternalIdentifierEntity.setClientSourceId(existingClientSourceId);
externalIdentifierDao.merge(updatedExternalIdentifierEntity);
return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(updatedExternalIdentifierEntity);
}
Aggregations