use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.
the class ApiDAOImpl method addDocumentInfo.
/**
* Add artifact resource meta data to an API
*
* @param apiId UUID of API
* @param documentInfo {@link DocumentInfo}
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void addDocumentInfo(String apiId, DocumentInfo documentInfo) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
ApiResourceDAO.addResourceWithoutValue(connection, apiId, documentInfo.getId(), ResourceCategory.DOC);
DocMetaDataDAO.addDocumentInfo(connection, documentInfo);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateDocumentInfo.
/**
* Add artifact resource meta data to an API
*
* @param apiId UUID of API
* @param documentInfo {@link DocumentInfo}
* @param updatedBy user who performs the action
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
@Override
public void updateDocumentInfo(String apiId, DocumentInfo documentInfo, String updatedBy) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
DocMetaDataDAO.updateDocInfo(connection, documentInfo, updatedBy);
connection.commit();
} catch (SQLException e) {
connection.rollback();
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String msg = "updating Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName() + ", updated by: " + updatedBy;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.
the class EntityDAO method getLastUpdatedTimeOfResourceByName.
/**
* Returns the last access time of the given entity identified by the NAME field.
*
* @param resourceTableName Table name of the entity
* @param name value in the NAME field of the entity
* @return Last access time of the requested resource
* @throws APIMgtDAOException
*/
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
static String getLastUpdatedTimeOfResourceByName(String resourceTableName, String name) throws APIMgtDAOException {
final String query = "SELECT LAST_UPDATED_TIME FROM " + resourceTableName + " WHERE NAME = ?";
String lastUpdatedTime = null;
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, name);
try (ResultSet rs = statement.executeQuery()) {
if (rs.next()) {
lastUpdatedTime = rs.getString("LAST_UPDATED_TIME");
}
}
return lastUpdatedTime;
} catch (SQLException e) {
throw new APIMgtDAOException("Error while retrieving last access time from table : " + resourceTableName + " and entity " + name, e);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method setApiResourceBuilderProperties.
/**
* Extract properties in Operation entry and assign them to api resource builder properties.
*
* @param operationEntry Map entry to be extracted properties
* @param uriTemplateBuilder Uri template builder to assign related properties
* @param resourcePath resource path
* @return APIResource.Builder object
*/
private APIResource.Builder setApiResourceBuilderProperties(Map.Entry<HttpMethod, Operation> operationEntry, UriTemplate.UriTemplateBuilder uriTemplateBuilder, String resourcePath) {
Operation operation = operationEntry.getValue();
APIResource.Builder apiResourceBuilder = new APIResource.Builder();
List<String> producesList = operation.getProduces();
if (producesList != null) {
String produceSeparatedString = "\"";
produceSeparatedString += String.join("\",\"", producesList) + "\"";
apiResourceBuilder.produces(produceSeparatedString);
}
List<String> consumesList = operation.getConsumes();
if (consumesList != null) {
String consumesSeparatedString = "\"";
consumesSeparatedString += String.join("\",\"", consumesList) + "\"";
apiResourceBuilder.consumes(consumesSeparatedString);
}
if (operation.getOperationId() != null) {
uriTemplateBuilder.templateId(operation.getOperationId());
} else {
uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(resourcePath, operationEntry.getKey().name()));
}
uriTemplateBuilder.httpVerb(operationEntry.getKey().name());
apiResourceBuilder.uriTemplate(uriTemplateBuilder.build());
return apiResourceBuilder;
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-apimgt by wso2.
the class APIExecutor method execute.
/**
* This method will be called when the invoke() method of the default lifecycle implementation is called.
* Execution logic should reside in this method since the default lifecycle implementation will determine
* the execution output by looking at the output of this method.
*
* @param resource The resource in which the lifecycle state is changed.
* @param currentState Current lifecycle state.
* @param targetState The target lifecycle state.
* @throws LifecycleException If exception occurs while running the executor.
*/
@Override
public void execute(Object resource, String currentState, String targetState) throws LifecycleException {
API api = (API) resource;
if (!currentState.equals(targetState)) {
// todo:This place need to write how to handle Gateway publishing
try {
ApiDAO apiDAO = DAOFactory.getApiDAO();
apiDAO.changeLifeCycleStatus(api.getId(), targetState);
} catch (APIMgtDAOException e) {
throw new LifecycleException("Couldn't create APIPublisher from user", e);
}
}
}
Aggregations