Search in sources :

Example 71 with APIProductIdentifier

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;
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) Identifier(org.wso2.carbon.apimgt.api.model.Identifier) ResultSet(java.sql.ResultSet) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 72 with APIProductIdentifier

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);
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Example 73 with 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;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) DocumentSearchResultDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.DocumentSearchResultDTO)

Example 74 with APIProductIdentifier

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;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO) JSONException(org.json.JSONException) XMLStreamException(javax.xml.stream.XMLStreamException) CertificateManagementException(org.wso2.carbon.apimgt.impl.certificatemgt.exceptions.CertificateManagementException) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException) APITemplateException(org.wso2.carbon.apimgt.impl.template.APITemplateException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) MediationPolicyDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.MediationPolicyDTO)

Example 75 with APIProductIdentifier

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);
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)91 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)48 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)33 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)22 PreparedStatement (java.sql.PreparedStatement)19 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)19 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)19 Connection (java.sql.Connection)18 ArrayList (java.util.ArrayList)18 ResultSet (java.sql.ResultSet)17 SQLException (java.sql.SQLException)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 API (org.wso2.carbon.apimgt.api.model.API)14 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)14 HashSet (java.util.HashSet)13 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)13 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)13 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)13 Tier (org.wso2.carbon.apimgt.api.model.Tier)12 PublisherAPIProduct (org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct)12