use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class SystemPropertiesCliResource method get.
@GET
public ActionReportResult get() {
domain = locatorBridge.getRemoteLocator().getService(Domain.class);
ParameterMap data = new ParameterMap();
processCommandParams(data);
addQueryString(uriInfo.getQueryParameters(), data);
adjustParameters(data);
Map<String, Map<String, String>> properties = new TreeMap<String, Map<String, String>>();
RestActionReporter actionReport = new RestActionReporter();
getSystemProperties(properties, getEntity(), false);
actionReport.getExtraProperties().put("systemProperties", new ArrayList(properties.values()));
if (properties.isEmpty()) {
// i18n
actionReport.getTopMessagePart().setMessage("Nothing to list.");
}
ActionReportResult results = new ActionReportResult(commandName, actionReport, new OptionsResult());
return results;
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class SystemPropertiesCliResource method saveProperties.
protected Response saveProperties(String parent, HashMap<String, String> data) {
String propertiesString = convertPropertyMapToString(data);
data = new HashMap<String, String>();
data.put("DEFAULT", propertiesString);
data.put("target", (parent == null) ? getParent(uriInfo) : parent);
RestActionReporter actionReport = ResourceUtil.runCommand("create-system-properties", data, getSubject());
ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
ActionReportResult results = new ActionReportResult(commandName, actionReport, new OptionsResult());
int status = HttpURLConnection.HTTP_OK;
/*200 - ok*/
if (exitCode == ActionReport.ExitCode.FAILURE) {
status = HttpURLConnection.HTTP_INTERNAL_ERROR;
}
return Response.status(status).entity(results).build();
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class ResourceUtil method runCommand.
/**
* Executes the specified __asadmin command.
* @param commandName
* @param parameters
* @param subject
* @param managedJob
* @return
*/
public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob) {
AsadminRecorderService asadminRecorderService = Globals.getDefaultHabitat().getService(AsadminRecorderService.class);
if (asadminRecorderService.isEnabled()) {
asadminRecorderService.recordAsadminCommand(commandName, parameters);
}
CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
RestActionReporter ar = new RestActionReporter();
final CommandInvocation commandInvocation = cr.getCommandInvocation(commandName, ar, subject);
if (managedJob) {
commandInvocation.managedJob();
}
commandInvocation.parameters(parameters).execute();
addCommandLog(ar, commandName, parameters);
return ar;
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class CollectionLeafResource method buildActionReportResult.
protected ActionReportResult buildActionReportResult() {
RestActionReporter ar = new RestActionReporter();
final String typeKey = upperCaseFirstLetter((decode(getName())));
ar.setActionDescription(typeKey);
ar.getExtraProperties().put("leafList", getEntity());
OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
Map<String, MethodMetaData> mmd = getMethodMetaData();
optionsResult.putMethodMetaData("GET", mmd.get("GET"));
optionsResult.putMethodMetaData("POST", mmd.get("POST"));
ResourceUtil.addMethodMetaData(ar, mmd);
return new ActionReportResult(ar, optionsResult);
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class CollectionLeafResource method runCommand.
private Response runCommand(String commandName, Map<String, String> data, String successMsgKey, String successMsg, String operationForbiddenMsgKey, String operationForbiddenMsg) {
try {
if (data.containsKey("error")) {
String errorMessage = localStrings.getLocalString("rest.request.parsing.error", "Unable to parse the input entity. Please check the syntax.");
return Response.status(400).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, errorMessage, requestHeaders, uriInfo)).build();
}
ResourceUtil.purgeEmptyEntries(data);
ResourceUtil.adjustParameters(data);
String attributeName = data.get("DEFAULT");
if (null != commandName) {
RestActionReporter actionReport = ResourceUtil.runCommand(commandName, data, getSubject());
ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
if (exitCode != ActionReport.ExitCode.FAILURE) {
String successMessage = localStrings.getLocalString(successMsgKey, successMsg, new Object[] { attributeName });
return Response.ok(ResourceUtil.getActionReportResult(actionReport, successMessage, requestHeaders, uriInfo)).build();
}
String errorMessage = getErrorMessage(data, actionReport);
return Response.status(400).entity(ResourceUtil.getActionReportResult(actionReport, errorMessage, requestHeaders, uriInfo)).build();
}
String message = localStrings.getLocalString(operationForbiddenMsgKey, operationForbiddenMsg, new Object[] { uriInfo.getAbsolutePath() });
return Response.status(403).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, message, requestHeaders, uriInfo)).build();
} catch (Exception e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations