use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeWebResource method deleteAttribute.
@DELETE
@Path(ApiConstants.INUM_PARAM_PATH)
@Operation(summary = "Delete gluu attribute", description = "Deletes a gluu attribute")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response deleteAttribute(@PathParam(ApiConstants.INUM) @NotNull String inum) {
log(logger, "Processing deleteAttribute()");
try {
Preconditions.checkNotNull(inum);
GluuAttribute gluuAttribute = attributeService.getAttributeByInum(inum);
if (gluuAttribute != null) {
attributeService.removeAttribute(gluuAttribute);
return Response.ok().build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeWebResource method updateAttribute.
@PUT
@Operation(summary = "Update new attribute", description = "Updates a gluu attribute")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuAttribute.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateAttribute(GluuAttribute gluuAttribute) {
log(logger, "Processing updateAttribute()");
try {
Preconditions.checkNotNull(gluuAttribute, "Attempt to update null attribute");
String inum = gluuAttribute.getInum();
GluuAttribute existingAttribute = attributeService.getAttributeByInum(inum);
if (existingAttribute != null) {
gluuAttribute.setInum(existingAttribute.getInum());
attributeService.updateAttribute(gluuAttribute);
return Response.ok(attributeService.getAttributeByInum(existingAttribute.getInum())).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeInventoryAction method submit.
public void submit() {
FacesContext facesContext = FacesContext.getCurrentInstance();
List<String> checkedItems = new ArrayList<String>();
for (GluuAttribute item : activeAttributeList) {
if (checked.get(item.getDn())) {
checkedItems.add(item.getDn());
}
}
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.setContentType("text/plain");
response.addHeader("Content-disposition", "attachment; filename=\"attributes.ldif\"");
try (ServletOutputStream os = response.getOutputStream()) {
ldifService.exportLDIFFile(checkedItems, os);
os.flush();
facesContext.responseComplete();
} catch (Exception e) {
log.error("\nFailure : " + e.toString() + "\n");
}
checked.clear();
}
use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class CustomAttributeAction method selectCustomAttributes.
private void selectCustomAttributes(List<GluuCustomAttribute> customAttributes) {
for (GluuCustomAttribute customAttribute : this.customAttributes) {
GluuAttribute tmpAttribute = attributeInums.get(customAttribute.getMetadata().getInum());
if ((tmpAttribute == null) || containsCustomAttribute(tmpAttribute)) {
continue;
}
String id = this.attributeIds.get(tmpAttribute);
this.availableAttributeIds.remove(id);
}
}
use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class CustomAttributeAction method validateAttributeValues.
public void validateAttributeValues(ComponentSystemEvent event) {
final FacesContext facesContext = FacesContext.getCurrentInstance();
final List<Object> values = new ArrayList<Object>();
event.getComponent().visitTree(VisitContext.createVisitContext(facesContext), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent target) {
if (target instanceof UIInput) {
GluuAttribute attribute = (GluuAttribute) target.getAttributes().get("attribute");
if (attribute != null) {
values.add(((UIInput) target).getValue());
}
}
return VisitResult.ACCEPT;
}
});
values.removeAll(Arrays.asList(null, ""));
Set<Object> uniqValues = new HashSet<Object>(values);
if (values.size() != uniqValues.size()) {
event.getComponent().visitTree(VisitContext.createVisitContext(facesContext), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent target) {
if (target instanceof UIInput) {
GluuAttribute attribute = (GluuAttribute) target.getAttributes().get("attribute");
if (attribute != null) {
((UIInput) target).setValid(false);
String message = "Please fill out an unique value for all of '" + attribute.getDisplayName() + "' fields";
facesMessages.add(target.getClientId(facesContext), FacesMessage.SEVERITY_ERROR, message);
}
}
return VisitResult.ACCEPT;
}
});
facesContext.validationFailed();
}
}
Aggregations