use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class PersonImportAction method save.
public String save() {
if (!organizationService.isAllowPersonModification()) {
return OxTrustConstants.RESULT_FAILURE;
}
personService.addCustomObjectClass(this.person);
if (personService.getPersonByUid(this.person.getUid()) != null) {
return OxTrustConstants.RESULT_DUPLICATE;
}
this.inum = personService.generateInumForNewPerson();
String iname = personService.generateInameForNewPerson(this.person.getUid());
String dn = personService.getDnForPerson(this.inum);
// Save person
this.person.setDn(dn);
this.person.setInum(this.inum);
this.person.setIname(iname);
List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
changedAttributes.addAll(personAttributes);
changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getDisplayName()));
this.person.setCustomAttributes(changedAttributes);
} else {
this.person.setCommonName(this.person.getCommonName() + " " + this.person.getGivenName());
}
try {
boolean runScript = externalUpdateUserService.isEnabled();
if (runScript) {
externalUpdateUserService.executeExternalAddUserMethods(this.person);
}
personService.addPerson(this.person);
if (runScript) {
externalUpdateUserService.executeExternalPostAddUserMethods(this.person);
}
} catch (Exception ex) {
log.error("Failed to add new person {}", this.person.getInum(), ex);
return OxTrustConstants.RESULT_FAILURE;
}
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class UpdatePersonAction method save.
/**
* Saves person to ldap
*
* @return String describing success of the operation
*/
public String save() throws Exception {
if (!organizationService.isAllowPersonModification()) {
return OxTrustConstants.RESULT_FAILURE;
}
if (!update) {
if (!validatePerson(this.person)) {
return OxTrustConstants.RESULT_FAILURE;
}
}
updateCustomObjectClasses();
List<GluuCustomAttribute> removedAttributes = customAttributeAction.detectRemovedAttributes();
customAttributeAction.updateOriginCustomAttributes();
List<GluuCustomAttribute> customAttributes = customAttributeAction.getCustomAttributes();
for (GluuCustomAttribute customAttribute : customAttributes) {
if (customAttribute.getName().equalsIgnoreCase("gluuStatus")) {
customAttribute.setValue(gluuStatus.getValue());
}
}
this.person.setCustomAttributes(customAttributeAction.getCustomAttributes());
this.person.getCustomAttributes().addAll(removedAttributes);
// Sync email, in reverse ("oxTrustEmail" <- "mail")
this.person = ServiceUtil.syncEmailReverse(this.person, true);
boolean runScript = externalUpdateUserService.isEnabled();
if (update) {
try {
if (runScript) {
externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
}
personService.updatePerson(this.person);
if (runScript) {
externalUpdateUserService.executeExternalPostUpdateUserMethods(this.person);
}
} catch (BaseMappingException ex) {
log.error("Failed to update person {}", inum, ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update person '#{updatePersonAction.person.displayName}'");
return OxTrustConstants.RESULT_FAILURE;
}
facesMessages.add(FacesMessage.SEVERITY_INFO, "Person '#{updatePersonAction.person.displayName}' updated successfully");
} else {
if (personService.getPersonByUid(this.person.getUid()) != null) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Person with the uid '#{updatePersonAction.person.uid}' already exist'");
return OxTrustConstants.RESULT_DUPLICATE;
}
this.inum = personService.generateInumForNewPerson();
String iname = personService.generateInameForNewPerson(this.person.getUid());
String dn = personService.getDnForPerson(this.inum);
// Save person
this.person.setDn(dn);
this.person.setInum(this.inum);
this.person.setIname(iname);
this.person.setUserPassword(this.password);
List<GluuCustomAttribute> personAttributes = this.person.getCustomAttributes();
if (!personAttributes.contains(new GluuCustomAttribute("cn", ""))) {
List<GluuCustomAttribute> changedAttributes = new ArrayList<GluuCustomAttribute>();
changedAttributes.addAll(personAttributes);
changedAttributes.add(new GluuCustomAttribute("cn", this.person.getGivenName() + " " + this.person.getDisplayName()));
this.person.setCustomAttributes(changedAttributes);
} else {
this.person.setCommonName(this.person.getCommonName() + " " + this.person.getGivenName());
}
try {
if (runScript) {
externalUpdateUserService.executeExternalAddUserMethods(this.person);
}
personService.addPerson(this.person);
if (runScript) {
externalUpdateUserService.executeExternalPostAddUserMethods(this.person);
}
} catch (Exception ex) {
log.error("Failed to add new person {}", this.person.getInum(), ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new person'");
return OxTrustConstants.RESULT_FAILURE;
}
facesMessages.add(FacesMessage.SEVERITY_INFO, "New person '#{updatePersonAction.person.displayName}' added successfully");
conversationService.endConversation();
this.update = true;
}
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class UserProfileAction method update.
public String update() {
try {
if (this.imapData != null) {
List<GluuCustomAttribute> customAttributes = this.person.getCustomAttributes();
for (GluuCustomAttribute gluuCustomAttribute : customAttributes) {
if (gluuCustomAttribute.getName().equals("gluuIMAPData")) {
gluuCustomAttribute.setValue(imapDataService.getJsonStringFromImap(this.imapData));
}
}
}
GluuCustomPerson person = this.person;
// TODO: Reffactor
person.setGluuOptOuts(optOuts.size() == 0 ? null : optOuts);
boolean runScript = externalUpdateUserService.isEnabled();
if (runScript) {
externalUpdateUserService.executeExternalUpdateUserMethods(this.person);
}
personService.updatePerson(this.person);
if (runScript) {
externalUpdateUserService.executeExternalPostUpdateUserMethods(this.person);
}
} catch (BaseMappingException ex) {
log.error("Failed to update profile {}", person.getInum(), ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update profile '#{userProfileAction.person.displayName}'");
return OxTrustConstants.RESULT_FAILURE;
}
customAttributeAction.savePhotos();
facesMessages.add(FacesMessage.SEVERITY_INFO, "Profile '#{userProfileAction.person.displayName}' updated successfully");
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class AttributeService method setAttributeMetadata.
/**
* Set metadata for every custom attribute
*
* @param customAttributes
* List of custom attributes
* @param attributes
* List of attributes
*/
public void setAttributeMetadata(List<GluuCustomAttribute> customAttributes, List<GluuAttribute> attributes) {
if ((customAttributes == null) || (attributes == null)) {
return;
}
for (GluuCustomAttribute personAttribute : customAttributes) {
GluuAttribute tmpAttribute = getAttributeByName(personAttribute.getName(), attributes);
if (tmpAttribute == null) {
log.error("Failed to find attribute '{}' metadata", personAttribute.getName());
}
personAttribute.setMetadata(tmpAttribute);
}
}
use of org.gluu.oxtrust.model.GluuCustomAttribute in project oxTrust by GluuFederation.
the class AttributeService method getCustomAttributesByAttributeDNs.
/**
* Get custom attributes by attribute DNs
*
* @param customAttributes
* List of attribute DNs
* @param attributes
* List of custom attributes
*/
public List<GluuCustomAttribute> getCustomAttributesByAttributeDNs(List<String> attributeDNs, HashMap<String, GluuAttribute> attributesByDNs) {
List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
if (attributeDNs == null) {
return customAttributes;
}
for (String releasedAttributeDn : attributeDNs) {
GluuAttribute attribute = attributesByDNs.get(releasedAttributeDn);
if (attribute != null) {
GluuCustomAttribute customAttribute = new GluuCustomAttribute(attribute.getName(), releasedAttributeDn);
customAttribute.setMetadata(attribute);
customAttributes.add(customAttribute);
}
}
return customAttributes;
}
Aggregations