use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class GraphQLSchemaDefinition method getGraphqlSchemaDefinition.
/**
* Returns the graphQL content in registry specified by the wsdl name
*
* @param apiId Api Identifier
* @return graphQL content matching name if exist else null
*/
public String getGraphqlSchemaDefinition(APIIdentifier apiId, Registry registry) throws APIManagementException {
String apiName = apiId.getApiName();
String apiVersion = apiId.getVersion();
String apiProviderName = apiId.getProviderName();
APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiId.getUUID());
String resourcePath;
if (apiRevision != null && apiRevision.getApiUUID() != null) {
resourcePath = APIUtil.getRevisionPath(apiRevision.getApiUUID(), apiRevision.getId());
} else {
resourcePath = APIUtil.getGraphqlDefinitionFilePath(apiName, apiVersion, apiProviderName);
}
String schemaDoc = null;
String schemaName = apiId.getProviderName() + APIConstants.GRAPHQL_SCHEMA_PROVIDER_SEPERATOR + apiId.getApiName() + apiId.getVersion() + APIConstants.GRAPHQL_SCHEMA_FILE_EXTENSION;
String schemaResourePath = resourcePath + schemaName;
try {
if (registry.resourceExists(schemaResourePath)) {
Resource schemaResource = registry.get(schemaResourePath);
schemaDoc = IOUtils.toString(schemaResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
}
} catch (RegistryException e) {
String msg = "Error while getting schema file from the registry " + schemaResourePath;
log.error(msg, e);
throw new APIManagementException(msg, e);
} catch (IOException e) {
String error = "Error occurred while getting the content of schema: " + schemaName;
log.error(error);
throw new APIManagementException(error, e);
}
return schemaDoc;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesMediationMediationPolicyIdGet.
/**
* Returns a specific global mediation policy by identifier
*
* @param mediationPolicyId Mediation policy uuid
* @param accept Accept header value
* @return returns the matched mediation
*/
@Override
public Response policiesMediationMediationPolicyIdGet(String mediationPolicyId, String accept, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
// Get given global mediation policy
Mediation mediation = apiProvider.getGlobalMediationPolicy(mediationPolicyId);
if (mediation != null) {
MediationDTO mediationDTO = MediationMappingUtil.fromMediationToDTO(mediation);
return Response.ok().entity(mediationDTO).build();
} else {
// If global mediation policy not exists
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_POLICY, mediationPolicyId, log);
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving the global mediation policy with id " + mediationPolicyId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImpl method workflowsExternalWorkflowRefGet.
/**
* This is used to get the workflow pending request according to ExternalWorkflowReference
*
* @param externalWorkflowRef is the unique identifier for workflow request
* @return
*/
@Override
public Response workflowsExternalWorkflowRefGet(String externalWorkflowRef, MessageContext messageContext) throws APIManagementException {
WorkflowInfoDTO workflowinfoDTO;
try {
Workflow workflow;
String status = "CREATED";
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
APIAdmin apiAdmin = new APIAdminImpl();
workflow = apiAdmin.getworkflowReferenceByExternalWorkflowReferenceID(externalWorkflowRef, status, tenantDomain);
workflowinfoDTO = WorkflowMappingUtil.fromWorkflowsToInfoDTO(workflow);
return Response.ok().entity(workflowinfoDTO).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving workflow request by the " + "external workflow reference. ", e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method deleteAPI.
public void deleteAPI(String uuid) throws APIManagementException {
Connection connection = null;
PreparedStatement prepStmt = null;
int id;
String deleteLCEventQuery = SQLConstants.REMOVE_FROM_API_LIFECYCLE_SQL;
String deleteAuditAPIMapping = SQLConstants.REMOVE_SECURITY_AUDIT_MAP_SQL;
String deleteCommentQuery = SQLConstants.REMOVE_FROM_API_COMMENT_SQL;
String deleteRatingsQuery = SQLConstants.REMOVE_FROM_API_RATING_SQL;
String deleteSubscriptionQuery = SQLConstants.REMOVE_FROM_API_SUBSCRIPTION_SQL;
String deleteExternalAPIStoresQuery = SQLConstants.REMOVE_FROM_EXTERNAL_STORES_SQL;
String deleteAPIQuery = SQLConstants.REMOVE_FROM_API_SQL_BY_UUID;
String deleteResourceScopeMappingsQuery = SQLConstants.REMOVE_RESOURCE_SCOPE_URL_MAPPING_SQL;
String deleteURLTemplateQuery = SQLConstants.REMOVE_FROM_API_URL_MAPPINGS_SQL;
String deleteGraphqlComplexityQuery = SQLConstants.REMOVE_FROM_GRAPHQL_COMPLEXITY_SQL;
try {
connection = APIMgtDBUtil.getConnection();
connection.setAutoCommit(false);
APIIdentifier identifier = ApiMgtDAO.getInstance().getAPIIdentifierFromUUID(uuid);
id = getAPIID(uuid, connection);
prepStmt = connection.prepareStatement(deleteAuditAPIMapping);
prepStmt.setInt(1, id);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
prepStmt = connection.prepareStatement(deleteGraphqlComplexityQuery);
prepStmt.setInt(1, id);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
prepStmt = connection.prepareStatement(deleteSubscriptionQuery);
prepStmt.setInt(1, id);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
// Delete all comments associated with given API
deleteAPIComments(id, uuid, connection);
prepStmt = connection.prepareStatement(deleteRatingsQuery);
prepStmt.setInt(1, id);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
prepStmt = connection.prepareStatement(deleteLCEventQuery);
prepStmt.setInt(1, id);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
// Delete all external APIStore details associated with a given API
prepStmt = connection.prepareStatement(deleteExternalAPIStoresQuery);
prepStmt.setInt(1, id);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
// Delete resource scope mappings of the API
prepStmt = connection.prepareStatement(deleteResourceScopeMappingsQuery);
prepStmt.setInt(1, id);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
// Delete URL Templates (delete the resource scope mappings on delete cascade)
prepStmt = connection.prepareStatement(deleteURLTemplateQuery);
prepStmt.setInt(1, id);
prepStmt.execute();
deleteAllAPISpecificOperationPoliciesByAPIUUID(connection, uuid, null);
prepStmt = connection.prepareStatement(deleteAPIQuery);
prepStmt.setString(1, uuid);
prepStmt.execute();
// If exception occurs at execute, this statement will close in finally else here
prepStmt.close();
String curDefaultVersion = getDefaultVersion(identifier);
String pubDefaultVersion = getPublishedDefaultVersion(identifier);
if (identifier.getVersion().equals(curDefaultVersion)) {
ArrayList<APIIdentifier> apiIdList = new ArrayList<APIIdentifier>() {
{
add(identifier);
}
};
removeAPIFromDefaultVersion(apiIdList, connection);
} else if (identifier.getVersion().equals(pubDefaultVersion)) {
setPublishedDefVersion(identifier, connection, null);
}
connection.commit();
} catch (SQLException e) {
handleException("Error while removing the API with UUID: " + uuid + " from the database", e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, null);
}
}
use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method getComments.
/**
**************************************
* Returns all the Comments on an API
*
* @param apiTypeWrapper API type Wrapper
* @param parentCommentID Parent Comment ID
* @return Comment Array
* @throws APIManagementException
*/
public CommentList getComments(ApiTypeWrapper apiTypeWrapper, String parentCommentID, Integer limit, Integer offset) throws APIManagementException {
CommentList commentList = null;
try (Connection connection = APIMgtDBUtil.getConnection()) {
int id = -1;
String uuid;
Identifier identifier;
String currentApiUuid;
if (apiTypeWrapper.isAPIProduct()) {
identifier = apiTypeWrapper.getApiProduct().getId();
uuid = apiTypeWrapper.getApiProduct().getUuid();
APIRevision apiRevision = checkAPIUUIDIsARevisionUUID(uuid);
if (apiRevision != null && apiRevision.getApiUUID() != null) {
currentApiUuid = apiRevision.getApiUUID();
} else {
currentApiUuid = uuid;
}
} else {
identifier = apiTypeWrapper.getApi().getId();
uuid = apiTypeWrapper.getApi().getUuid();
APIRevision apiRevision = checkAPIUUIDIsARevisionUUID(uuid);
if (apiRevision != null && apiRevision.getApiUUID() != null) {
currentApiUuid = apiRevision.getApiUUID();
} else {
currentApiUuid = uuid;
}
}
id = getAPIID(currentApiUuid, connection);
if (id == -1) {
String msg = "Could not load API record for: " + identifier.getName();
throw new APIManagementException(msg);
}
commentList = getComments(currentApiUuid, parentCommentID, limit, offset, connection);
} catch (SQLException e) {
handleException("Failed to retrieve comments for " + apiTypeWrapper.getName(), e);
}
return commentList;
}
Aggregations