use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class TemplateRestResource method doDelete.
protected ExitCode doDelete(HashMap<String, String> data) {
if (data == null) {
data = new HashMap<String, String>();
}
if (entity == null) {
// wrong resource
// return Response.status(404).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, errorMessage, requestHeaders, uriInfo)).build();
throwError(Status.NOT_FOUND, localStrings.getLocalString("rest.resource.erromessage.noentity", "Resource not found."));
}
if (getDeleteCommand() == null) {
String message = localStrings.getLocalString("rest.resource.delete.forbidden", "DELETE on \"{0}\" is forbidden.", new Object[] { uriInfo.getAbsolutePath() });
throwError(Status.FORBIDDEN, message);
}
if (getDeleteCommand().equals("GENERIC-DELETE")) {
try {
ConfigBean p = (ConfigBean) parent;
if (parent == null) {
p = (ConfigBean) entity.parent();
}
ConfigSupport.deleteChild(p, (ConfigBean) entity);
return ExitCode.SUCCESS;
} catch (TransactionFailure ex) {
throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
}
}
// do the delete via the command:
if (data.containsKey("error")) {
throwError(Status.BAD_REQUEST, localStrings.getLocalString("rest.request.parsing.error", "Unable to parse the input entity. Please check the syntax."));
}
ResourceUtil.addQueryString(uriInfo.getQueryParameters(), data);
ResourceUtil.purgeEmptyEntries(data);
ResourceUtil.adjustParameters(data);
if (data.get("DEFAULT") == null) {
addDefaultParameter(data);
} else {
String resourceName = getResourceName(uriInfo.getAbsolutePath().getPath(), "/");
if (!data.get("DEFAULT").equals(resourceName)) {
throwError(Status.FORBIDDEN, localStrings.getLocalString("rest.resource.not.deleted", "Resource not deleted. Value of \"name\" should be the name of this resource."));
}
}
RestActionReporter actionReport = runCommand(getDeleteCommand(), data);
if (actionReport != null) {
ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
if (exitCode != ActionReport.ExitCode.FAILURE) {
return exitCode;
}
throwError(Status.BAD_REQUEST, actionReport.getMessage());
}
throw new WebApplicationException(handleError(Status.BAD_REQUEST, localStrings.getLocalString("rest.resource.delete.forbidden", "DELETE on \"{0}\" is forbidden.", new Object[] { uriInfo.getAbsolutePath() })));
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class ManagementProxyResource method proxyRequest.
@GET
public ActionReportResult proxyRequest() {
RestActionReporter ar = new RestActionReporter();
ar.setActionDescription("Proxied Data");
ar.setSuccess();
ActionReportResult result = new ActionReportResult(ar);
Properties proxiedResponse = new ManagementProxyImpl().proxyRequest(uriInfo, Util.getJerseyClient(), habitat);
ar.setExtraProperties(proxiedResponse);
return result;
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class MonitoredAttributeBagResource method setMonitoredAttributes.
/**
* Sets the monitored attribute list to the specified list.
*
* @param attributes the intended list of attributes.
* @throws TransactionFailure if an error occurs in removing or adding
* attributes.
*/
public void setMonitoredAttributes(List<Map<String, String>> attributes) throws TransactionFailure {
TranslatedConfigView.doSubstitution.set(false);
List<Map<String, String>> existingAttributes = getMonitoredAttributes();
// Get a list of attributes that need adding
List<Map<String, String>> attributesToAdd = new ArrayList<>(attributes);
// Start with the list of specified attributes, and remove any that are also in the existing list
Iterator<Map<String, String>> iterator = attributesToAdd.iterator();
while (iterator.hasNext()) {
Map<String, String> attributeToAdd = iterator.next();
for (Map<String, String> existingAttribute : existingAttributes) {
if (attributesAreEqual(existingAttribute, attributeToAdd)) {
iterator.remove();
}
}
}
// Get a list of attributes that need deleting
List<Map<String, String>> attributesToDelete = new ArrayList<>(existingAttributes);
// Start with the list of existing attributes, and remove any that aren't also in the specified list
iterator = attributesToDelete.iterator();
while (iterator.hasNext()) {
Map<String, String> attributeToDelete = iterator.next();
boolean specified = false;
for (Map<String, String> specifiedAttribute : attributes) {
if (attributesAreEqual(specifiedAttribute, attributeToDelete)) {
specified = true;
}
}
if (specified) {
iterator.remove();
}
}
try {
// Add all required attributes
for (Map<String, String> attribute : attributesToAdd) {
Map<String, String> parameters = new HashMap<>();
parameters.put("addattribute", String.format("attributeName=%s objectName=%s", attribute.get("attributeName"), attribute.get("objectName")));
RestActionReporter reporter = ResourceUtil.runCommand("set-monitoring-configuration", parameters, getSubject());
if (reporter.isFailure()) {
throw new TransactionFailure(reporter.getMessage());
}
}
// Delete all unrequired attributes
for (Map<String, String> attribute : attributesToDelete) {
Map<String, String> parameters = new HashMap<>();
parameters.put("delattribute", String.format("attributeName=%s objectName=%s", attribute.get("attributeName"), attribute.get("objectName")));
RestActionReporter reporter = ResourceUtil.runCommand("set-monitoring-configuration", parameters, getSubject());
if (reporter.isFailure()) {
throw new TransactionFailure(reporter.getMessage());
}
}
} finally {
TranslatedConfigView.doSubstitution.set(true);
}
synchronized (parent) {
entity = parent.nodeElements("monitored-attributes");
}
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class MonitoredAttributeBagResource method put.
/**
* Creates new monitored-attributes. This method deletes all of the existing
* monitored-attributes.
*
* @param attributes the list of monitored-attributes to be created.
* @return a list of the monitored-attributes after the transaction.
*/
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ActionReportResult put(List<Map<String, String>> attributes) {
RestActionReporter ar = new RestActionReporter();
ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ar.setActionDescription("monitored-attribute");
try {
setMonitoredAttributes(attributes);
List monitoredAttributes = getMonitoredAttributes();
Properties extraProperties = new Properties();
extraProperties.put("monitoredAttributes", monitoredAttributes);
ar.setExtraProperties(extraProperties);
} catch (TransactionFailure ex) {
ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
ar.setMessage(ex.getMessage());
}
return new ActionReportResult(tagName, ar, new OptionsResult(Util.getResourceName(uriInfo)));
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class MonitoredAttributeBagResource method get.
/**
* Gets the monitored-attributes.
*
* @return a list of the monitored-attributes after the transaction.
*/
@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ActionReportResult get() {
RestActionReporter ar = new RestActionReporter();
ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ar.setActionDescription("monitored-attribute");
List monitoredAttributes = getMonitoredAttributes();
Properties extraProperties = new Properties();
extraProperties.put("monitoredAttributes", monitoredAttributes);
ar.setExtraProperties(extraProperties);
return new ActionReportResult(tagName, ar, new OptionsResult(Util.getResourceName(uriInfo)));
}
Aggregations