/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
-import org.onap.policy.apex.model.utilities.TextFileUtils;
+import org.onap.policy.common.utils.resources.TextFileUtils;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
*
*/
@Path("editor/{session}")
-@Produces(
- { MediaType.APPLICATION_JSON })
-@Consumes(
- { MediaType.APPLICATION_JSON })
+@Produces({MediaType.APPLICATION_JSON})
+@Consumes({MediaType.APPLICATION_JSON})
public class ApexEditorRestResource implements RestCommandHandler {
// Get a reference to the logger
/**
* Retrieve the model for this session. If successful the model will be available in the first message in the
- * result. The returned value will be similar to a {@code AxPolicyModel}, with merged {@code AxKeyInfo} for the
- * root object.
+ * result. The returned value will be similar to a {@code AxPolicyModel}, with merged {@code AxKeyInfo} for the root
+ * object.
*
* @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
* messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
@GET
@Path("KeyInformation/Get")
public ApexApiResult listKeyInformation(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.KEY_INFO, RestCommand.LIST, name, version);
}
/**
* List context schemas with the given key names/versions. If successful the result(s) will be available in the
- * result messages. The returned value(s) will be similar to {@code AxContextSchema}, with merged
- * {@code AxKeyInfo} for the root object.
+ * result messages. The returned value(s) will be similar to {@code AxContextSchema}, with merged {@code AxKeyInfo}
+ * for the root object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
@GET
@Path("ContextSchema/Get")
public ApexApiResult listContextSchemas(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.LIST, name, version);
}
@DELETE
@Path("ContextSchema/Delete")
public ApexApiResult deleteContextSchema(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.DELETE, name, version);
}
@GET
@Path("Validate/ContextSchema")
public ApexApiResult validateContextSchemas(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.VALIDATE, name, version);
}
/**
* List context albums with the given key names/versions. If successful the result(s) will be available in the
- * result messages. The returned value(s) will be similar to {@code AxContextAlbum}, with merged
- * {@code AxKeyInfo} for the root object.
+ * result messages. The returned value(s) will be similar to {@code AxContextAlbum}, with merged {@code AxKeyInfo}
+ * for the root object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
@GET
@Path("ContextAlbum/Get")
public ApexApiResult listContextAlbums(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.LIST, name, version);
}
@DELETE
@Path("ContextAlbum/Delete")
public ApexApiResult deleteContextAlbum(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.DELETE, name, version);
}
@GET
@Path("Validate/ContextAlbum")
public ApexApiResult validateContextAlbums(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.VALIDATE, name, version);
}
/**
* List events with the given key names/versions. If successful the result(s) will be available in the result
- * messages. The returned value(s) will be similar to {@code AxEvent}, with merged {@code AxKeyInfo} for the
- * root object.
+ * messages. The returned value(s) will be similar to {@code AxEvent}, with merged {@code AxKeyInfo} for the root
+ * object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
/**
* List tasks with the given key names/versions. If successful the result(s) will be available in the result
- * messages. The returned value(s) will be similar to {@code AxTask}, with merged {@code AxKeyInfo} for the
- * root object.
+ * messages. The returned value(s) will be similar to {@code AxTask}, with merged {@code AxKeyInfo} for the root
+ * object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
@PUT
@Path("Policy/Update")
public ApexApiResult updatePolicy(@QueryParam("firstStatePeriodic") final boolean firstStatePeriodic,
- final String jsonString) {
+ final String jsonString) {
ApexApiResult result = processRestCommand(RestCommandType.POLICY, RestCommand.UPDATE, jsonString);
if (result != null && result.isOk() && firstStatePeriodic) {
/**
* List policies with the given key names/versions. If successful the result(s) will be available in the result
- * messages. The returned value(s) will be similar to {@code AxPolicy}, with merged {@code AxKeyInfo} for the
- * root object.
+ * messages. The returned value(s) will be similar to {@code AxPolicy}, with merged {@code AxKeyInfo} for the root
+ * object.
*
* @param name the name to search for. If null or empty, then all names will be queried
* @param version the version to search for. If null then all versions will be searched for.
/**
* This method routes REST commands that take no parameters to their caller.
- *
+ *
* @param commandType the type of REST command to process
* @param command the REST command to process
* @return the result of the REST command
/**
* This method routes REST commands that take a JSON string to their caller.
- *
+ *
* @param commandType the type of REST command to process
* @param command the REST command to process
* @param jsonString the JSON string received in the REST request
* @return the result of the REST command
*/
private ApexApiResult processRestCommand(final RestCommandType commandType, final RestCommand command,
- final String jsonString) {
+ final String jsonString) {
LOGGER.entry(commandType, jsonString);
try {
ApexApiResult result = new ApexApiResult();
/**
* This method routes REST commands that take a name and version to their caller.
- *
+ *
* @param commandType the type of REST command to process
* @param command the REST command to process
* @param name the name received in the REST request
* @return the result of the REST command
*/
private ApexApiResult processRestCommand(final RestCommandType commandType, final RestCommand command,
- final String name, final String version) {
+ final String name, final String version) {
LOGGER.entry(commandType, name, version);
try {
ApexApiResult result = new ApexApiResult();
*/
@Override
public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
- final RestCommand command) {
+ final RestCommand command) {
switch (commandType) {
case MODEL:
return MODEL_HANDLER.executeRestCommand(session, commandType, command);
/**
* This method invokes callers to run REST commands that take a JSON string.
- *
+ *
* @param session the Apex editor session
* @param commandType the type of REST command to process
* @param command the REST command to process
*/
@Override
public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
- final RestCommand command, final String jsonString) {
+ final RestCommand command, final String jsonString) {
switch (commandType) {
case MODEL:
return MODEL_HANDLER.executeRestCommand(session, commandType, command, jsonString);
/**
* This method invokes callers to run REST commands that take a name and version.
- *
+ *
* @param session the Apex editor session
* @param commandType the type of REST command to process
* @param command the REST command to process
*/
@Override
public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
- final RestCommand command, final String name, final String version) {
+ final RestCommand command, final String name, final String version) {
switch (commandType) {
case MODEL:
return MODEL_HANDLER.executeRestCommand(session, commandType, command, name, version);
periodicEventJsonString = TextFileUtils.getTextFileAsString(PERIODIC_EVENT_TEMPLATE);
} catch (IOException ioException) {
String message = "read of periodic event tempalte from " + PERIODIC_EVENT_TEMPLATE + "failed: "
- + ioException.getMessage();
+ + ioException.getMessage();
LOGGER.debug(message, ioException);
return new ApexApiResult(Result.FAILED, message);
}
return processRestCommand(RestCommandType.EVENT, RestCommand.CREATE, periodicEventJsonString);
}
-
+
/*
* This method is used only for testing and is used to cause an exception on calls from unit test to test exception
* handling.