}
try {
if (data.containsKey("error")) {
String errorMessage = localStrings.getLocalString("rest.request.parsing.error",
"Unable to parse the input entity. Please check the syntax.");
ActionReportResult arr = ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, errorMessage, requestHeaders, uriInfo);
return Response.status(400).entity(arr).build();
}
ResourceUtil.purgeEmptyEntries(data);
//Command to execute
String commandName = getPostCommand();
String resourceToCreate = uriInfo.getAbsolutePath() + "/";
if (null != commandName) {
ResourceUtil.adjustParameters(data); //adjusting for DEFAULT is required only while executing a CLI command
if (data.containsKey("name")) {
resourceToCreate += data.get("name");
} else {
resourceToCreate += data.get("DEFAULT");
}
String typeOfResult = ResourceUtil.getResultType(requestHeaders);
RestActionReporter actionReport = ResourceUtil.runCommand(commandName, data, locatorBridge.getRemoteLocator(), typeOfResult);
ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
if (exitCode != ActionReport.ExitCode.FAILURE) {
String successMessage =
localStrings.getLocalString("rest.resource.create.message",
"\"{0}\" created successfully.", resourceToCreate);
ActionReportResult arr = ResourceUtil.getActionReportResult(actionReport, successMessage, requestHeaders, uriInfo);
return Response.ok(arr).build();
}
String errorMessage = getErrorMessage(data, actionReport);
ActionReportResult arr = ResourceUtil.getActionReportResult(actionReport, errorMessage, requestHeaders, uriInfo);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(arr).build();
} else {
ActionReportResult arr = ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, "No CRUD Create possible.", requestHeaders, uriInfo);
return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(arr).build();
}
} catch (Exception e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}