use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class ApiMgtDAO method getSubscriptionByUUID.
/**
* returns the SubscribedAPI object which is related to the UUID
*
* @param uuid UUID of Application
* @return {@link SubscribedAPI} Object which contains the subscribed API information.
* @throws APIManagementException
*/
public SubscribedAPI getSubscriptionByUUID(String uuid) throws APIManagementException {
Connection conn = null;
ResultSet resultSet = null;
PreparedStatement ps = null;
try {
conn = APIMgtDBUtil.getConnection();
String getSubscriptionQuery = SQLConstants.GET_SUBSCRIPTION_BY_UUID_SQL;
ps = conn.prepareStatement(getSubscriptionQuery);
ps.setString(1, uuid);
resultSet = ps.executeQuery();
SubscribedAPI subscribedAPI = null;
if (resultSet.next()) {
Identifier identifier;
if (APIConstants.API_PRODUCT.equals(resultSet.getString("API_TYPE"))) {
identifier = new APIProductIdentifier(APIUtil.replaceEmailDomain(resultSet.getString("API_PROVIDER")), resultSet.getString("API_NAME"), resultSet.getString("API_VERSION"));
} else {
identifier = new APIIdentifier(APIUtil.replaceEmailDomain(resultSet.getString("API_PROVIDER")), resultSet.getString("API_NAME"), resultSet.getString("API_VERSION"));
}
identifier.setId(resultSet.getInt("API_ID"));
identifier.setUuid(resultSet.getString("API_UUID"));
identifier.setOrganization(resultSet.getString("ORGANIZATION"));
int applicationId = resultSet.getInt("APPLICATION_ID");
Application application = getLightweightApplicationById(conn, applicationId);
application.setSubscriptionCount(getSubscriptionCountByApplicationId(conn, application, identifier.getOrganization()));
subscribedAPI = new SubscribedAPI(application.getSubscriber(), identifier);
subscribedAPI.setUUID(resultSet.getString("UUID"));
subscribedAPI.setSubscriptionId(resultSet.getInt("SUBSCRIPTION_ID"));
subscribedAPI.setSubStatus(resultSet.getString("SUB_STATUS"));
subscribedAPI.setSubCreatedStatus(resultSet.getString("SUBS_CREATE_STATE"));
subscribedAPI.setTier(new Tier(resultSet.getString("TIER_ID")));
subscribedAPI.setRequestedTier(new Tier(resultSet.getString("TIER_ID_PENDING")));
Timestamp createdTime = resultSet.getTimestamp("CREATED_TIME");
subscribedAPI.setCreatedTime(createdTime == null ? null : String.valueOf(createdTime.getTime()));
try {
Timestamp updatedTime = resultSet.getTimestamp("UPDATED_TIME");
subscribedAPI.setUpdatedTime(updatedTime == null ? null : String.valueOf(updatedTime.getTime()));
} catch (SQLException e) {
// fixing Timestamp issue with default value '0000-00-00 00:00:00'for existing applications created
subscribedAPI.setUpdatedTime(subscribedAPI.getCreatedTime());
}
subscribedAPI.setApplication(application);
}
return subscribedAPI;
} catch (SQLException e) {
handleException("Failed to retrieve subscription from subscription id", e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, resultSet);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class ImportUtils method retrieveApiProductToOverwrite.
/**
* This method retrieves an API Product to overwrite in the current tenant domain.
*
* @param apiProductName API Product Name
* @param currentTenantDomain Current tenant domain
* @param apiProvider API Provider
* @param ignoreAndImport This should be true if the exception should be ignored
* @param organization Identifier of the organization
* @throws APIManagementException If an error occurs when retrieving the API to overwrite
*/
private static APIProduct retrieveApiProductToOverwrite(String apiProductName, String currentTenantDomain, APIProvider apiProvider, Boolean ignoreAndImport, String organization) throws APIManagementException {
String provider = APIUtil.getAPIProviderFromAPINameVersionTenant(apiProductName, ImportExportConstants.DEFAULT_API_PRODUCT_VERSION, currentTenantDomain);
APIProductIdentifier apiProductIdentifier = new APIProductIdentifier(APIUtil.replaceEmailDomain(provider), apiProductName, ImportExportConstants.DEFAULT_API_PRODUCT_VERSION);
// Checking whether the API exists
if (!apiProvider.isAPIProductAvailable(apiProductIdentifier, organization)) {
if (ignoreAndImport) {
return null;
}
throw new APIMgtResourceNotFoundException("Error occurred while retrieving the API Product. API Product: " + apiProductName + StringUtils.SPACE + APIConstants.API_DATA_VERSION + ": " + ImportExportConstants.DEFAULT_API_PRODUCT_VERSION + " not found");
}
return apiProvider.getAPIProduct(apiProductIdentifier);
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class SearchResultMappingUtil method fromDocumentationToProductDocumentResultDTO.
public static DocumentSearchResultDTO fromDocumentationToProductDocumentResultDTO(Documentation document, APIProduct apiProduct) throws APIManagementException {
DocumentSearchResultDTO docResultDTO = new DocumentSearchResultDTO();
docResultDTO.setId(document.getId());
docResultDTO.setName(document.getName());
docResultDTO.setDocType(DocumentSearchResultDTO.DocTypeEnum.valueOf(document.getType().toString()));
docResultDTO.setType(SearchResultDTO.TypeEnum.DOC);
docResultDTO.associatedType(APIConstants.AuditLogConstants.API_PRODUCT);
docResultDTO.setSummary(document.getSummary());
docResultDTO.setVisibility(mapVisibilityFromDocumentToDTO(document.getVisibility()));
docResultDTO.setSourceType(mapSourceTypeFromDocumentToDTO(document.getSourceType()));
docResultDTO.setOtherTypeName(document.getOtherTypeName());
APIProductIdentifier apiId = apiProduct.getId();
docResultDTO.setApiName(apiId.getName());
docResultDTO.setApiVersion(apiId.getVersion());
docResultDTO.setApiProvider(APIUtil.replaceEmailDomainBack(apiId.getProviderName()));
docResultDTO.setApiUUID(apiProduct.getUuid());
return docResultDTO;
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method retrieveSequence.
private static GatewayContentDTO retrieveSequence(APIProduct apiProduct, String pathToAchieve, List<MediationPolicyDTO> mediationPolicies, String type, API api) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = apiProduct.getId();
MediationPolicyDTO mediationPolicyDTO = null;
for (MediationPolicyDTO mediationPolicy : mediationPolicies) {
if (type.equalsIgnoreCase(mediationPolicy.getType())) {
mediationPolicyDTO = mediationPolicy;
break;
}
}
if (mediationPolicyDTO != null) {
GatewayContentDTO sequenceContentDto = new GatewayContentDTO();
String sequenceContent = ImportUtils.retrieveSequenceContent(pathToAchieve, !mediationPolicyDTO.isShared(), type.toLowerCase(), mediationPolicyDTO.getName());
if (StringUtils.isNotEmpty(sequenceContent)) {
try {
OMElement omElement = APIUtil.buildOMElement(new ByteArrayInputStream(sequenceContent.getBytes()));
if (omElement != null) {
String seqExt = APIUtil.getSequenceExtensionName(apiProductIdentifier.getName(), apiProductIdentifier.getVersion()).concat("--").concat(api.getUuid());
if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_OUT_EXT;
} else if (APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN.equalsIgnoreCase(type)) {
seqExt = seqExt + APIConstants.API_CUSTOM_SEQ_IN_EXT;
}
if (omElement.getAttribute(new QName("name")) != null) {
omElement.getAttribute(new QName("name")).setAttributeValue(seqExt);
}
sequenceContentDto.setName(seqExt);
sequenceContentDto.setContent(APIUtil.convertOMtoString(omElement));
return sequenceContentDto;
}
} catch (Exception e) {
throw new APIManagementException(e);
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier in project carbon-apimgt by wso2.
the class ImportExportAPIServiceImpl method exportAPIProduct.
@Override
public File exportAPIProduct(String apiId, String revisionUUID, boolean preserveStatus, ExportFormat format, boolean preserveDocs, boolean preserveCredentials, String organization) throws APIManagementException, APIImportExportException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String userName = RestApiCommonUtil.getLoggedInUsername();
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiId);
APIProduct product = apiProvider.getAPIProductbyUUID(revisionUUID, organization);
APIProductDTO apiProductDtoToReturn = APIMappingUtil.fromAPIProducttoDTO(product);
return ExportUtils.exportApiProduct(apiProvider, apiProductIdentifier, apiProductDtoToReturn, userName, format, preserveStatus, preserveDocs, preserveCredentials, organization);
}
Aggregations