Search in sources :

Example 51 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.

the class APIProviderImplTest method testGetAllPaginatedAPIs.

@Test
public void testGetAllPaginatedAPIs() throws RegistryException, UserStoreException, APIManagementException, XMLStreamException {
    APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
    API api1 = new API(apiId1);
    api1.setContext("/test");
    APIIdentifier apiId2 = new APIIdentifier("admin", "API2", "1.0.0");
    API api2 = new API(apiId2);
    api2.setContext("/test1");
    PaginationContext paginationCtx = Mockito.mock(PaginationContext.class);
    PowerMockito.when(PaginationContext.getInstance()).thenReturn(paginationCtx);
    Mockito.when(paginationCtx.getLength()).thenReturn(2);
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    ServiceReferenceHolder sh = TestUtils.getServiceReferenceHolder();
    RegistryService registryService = Mockito.mock(RegistryService.class);
    PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
    UserRegistry userReg = Mockito.mock(UserRegistry.class);
    PowerMockito.when(registryService.getGovernanceUserRegistry(CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME, -1234)).thenReturn(userReg);
    PowerMockito.when(APIUtil.getArtifactManager(userReg, APIConstants.API_KEY)).thenReturn(artifactManager);
    APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
    APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
    PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
    PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
    PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_PUBLISHER_APIS_PER_PAGE)).thenReturn("2");
    RealmService realmService = Mockito.mock(RealmService.class);
    TenantManager tm = Mockito.mock(TenantManager.class);
    PowerMockito.when(sh.getRealmService()).thenReturn(realmService);
    PowerMockito.when(realmService.getTenantManager()).thenReturn(tm);
    PowerMockito.when(tm.getTenantId("carbon.super")).thenReturn(-1234);
    GenericArtifact genericArtifact1 = Mockito.mock(GenericArtifact.class);
    GenericArtifact genericArtifact2 = Mockito.mock(GenericArtifact.class);
    Mockito.when(APIUtil.getAPI(genericArtifact1)).thenReturn(api1);
    Mockito.when(APIUtil.getAPI(genericArtifact2)).thenReturn(api2);
    List<GovernanceArtifact> governanceArtifacts = new ArrayList<GovernanceArtifact>();
    governanceArtifacts.add(genericArtifact1);
    governanceArtifacts.add(genericArtifact2);
    List<GovernanceArtifact> governanceArtifacts1 = new ArrayList<GovernanceArtifact>();
    PowerMockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyMap(), any(Registry.class), Mockito.anyString())).thenReturn(governanceArtifacts, governanceArtifacts1);
    Map<String, Object> result = apiProvider.getAllPaginatedAPIs("carbon.super", 0, 10);
    List<API> apiList = (List<API>) result.get("apis");
    Assert.assertEquals(2, apiList.size());
    Assert.assertEquals("API1", apiList.get(0).getId().getApiName());
    Assert.assertEquals("API2", apiList.get(1).getId().getApiName());
    Assert.assertEquals(2, result.get("totalLength"));
    // No APIs available
    Map<String, Object> result1 = apiProvider.getAllPaginatedAPIs("carbon.super", 0, 10);
    List<API> apiList1 = (List<API>) result1.get("apis");
    Assert.assertEquals(0, apiList1.size());
    // Registry Exception while retrieving artifacts
    Mockito.when(artifactManager.findGenericArtifacts(Matchers.anyMap())).thenThrow(RegistryException.class);
    try {
        apiProvider.getAllPaginatedAPIs("carbon.super", 0, 10);
    } catch (APIManagementException e) {
        Assert.assertEquals("Failed to get all APIs", e.getMessage());
    }
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) PaginationContext(org.wso2.carbon.registry.core.pagination.PaginationContext) GovernanceArtifact(org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact) ArrayList(java.util.ArrayList) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) RealmService(org.wso2.carbon.user.core.service.RealmService) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 52 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.

the class ExportUtils method addDependentAPIsToArchive.

/**
 * Retrieve dependent APIs by checking the resources of the API Product and store those in the archive directory.
 *
 * @param archivePath           Temp location to save the API artifacts
 * @param apiProductDtoToReturn API Product DTO which the resources should be considered
 * @param userName              User name of the requester
 * @param provider              API Product Provider
 * @param exportFormat          Export format of the API meta data, could be yaml or json
 * @param isStatusPreserved     Whether API status is preserved while export
 * @param organization          Organization
 * @throws APIImportExportException If an error occurs while creating the directory or extracting the archive
 * @throws APIManagementException   If an error occurs while retrieving API related resources
 */
public static void addDependentAPIsToArchive(String archivePath, APIProductDTO apiProductDtoToReturn, ExportFormat exportFormat, APIProvider provider, String userName, Boolean isStatusPreserved, boolean preserveDocs, boolean preserveCredentials, String organization) throws APIImportExportException, APIManagementException {
    String apisDirectoryPath = archivePath + File.separator + ImportExportConstants.APIS_DIRECTORY;
    CommonUtil.createDirectory(apisDirectoryPath);
    List<ProductAPIDTO> apisList = apiProductDtoToReturn.getApis();
    for (ProductAPIDTO productAPIDTO : apisList) {
        String apiProductRequesterDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
        API api = provider.getAPIbyUUID(productAPIDTO.getApiId(), apiProductRequesterDomain);
        APIDTO apiDtoToReturn = APIMappingUtil.fromAPItoDTO(api, preserveCredentials, null);
        File dependentAPI = exportApi(provider, api.getId(), apiDtoToReturn, api, userName, exportFormat, isStatusPreserved, preserveDocs, StringUtils.EMPTY, organization);
        CommonUtil.extractArchive(dependentAPI, apisDirectoryPath);
    }
}
Also used : ProductAPIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ProductAPIDTO) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) API(org.wso2.carbon.apimgt.api.model.API) ProductAPIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ProductAPIDTO) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) File(java.io.File)

Example 53 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.

the class InMemoryAPIDeployer method retrieveArtifact.

private GatewayAPIDTO retrieveArtifact(String apiId, Set<String> gatewayLabels) throws ArtifactSynchronizerException {
    GatewayAPIDTO result;
    String labelString = String.join("|", gatewayLabels);
    String encodedString = Base64.encodeBase64URLSafeString(labelString.getBytes());
    if (artifactRetriever != null) {
        try {
            String gatewayRuntimeArtifact = artifactRetriever.retrieveArtifact(apiId, encodedString);
            if (StringUtils.isNotEmpty(gatewayRuntimeArtifact)) {
                result = new Gson().fromJson(gatewayRuntimeArtifact, GatewayAPIDTO.class);
            } else {
                String msg = "Error retrieving artifacts for API " + apiId + ". Storage returned null";
                log.error(msg);
                throw new ArtifactSynchronizerException(msg);
            }
        } catch (ArtifactSynchronizerException e) {
            String msg = "Error deploying " + apiId + " in Gateway";
            log.error(msg, e);
            throw new ArtifactSynchronizerException(msg, e);
        }
    } else {
        String msg = "Artifact retriever not found";
        log.error(msg);
        throw new ArtifactSynchronizerException(msg);
    }
    return result;
}
Also used : GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) Gson(com.google.gson.Gson)

Example 54 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.

the class EndPointsApiServiceImpl method getEndpoints.

public Response getEndpoints(String apiName, String version, String tenantDomain, MessageContext messageContext) throws APIManagementException {
    tenantDomain = RestApiCommonUtil.getValidateTenantDomain(tenantDomain);
    List<String> deployedEndpoints = GatewayUtils.retrieveDeployedEndpoints(apiName, version, tenantDomain);
    if (debugEnabled) {
        log.debug("Retrieved Artifacts for " + apiName + " from eventhub");
    }
    EndpointsDTO endpointsDTO = new EndpointsDTO();
    endpointsDTO.endpoints(deployedEndpoints);
    return Response.ok().entity(endpointsDTO).build();
}
Also used : EndpointsDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.EndpointsDTO)

Example 55 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.

the class LocalEntryApiServiceImpl method getLocalEntries.

public Response getLocalEntries(String apiName, String version, String tenantDomain, MessageContext messageContext) throws APIManagementException {
    tenantDomain = RestApiCommonUtil.getValidateTenantDomain(tenantDomain);
    List<String> deployedLocalEntries = GatewayUtils.retrieveDeployedLocalEntries(apiName, version, tenantDomain);
    if (debugEnabled) {
        log.debug("Retrieved Artifacts for " + apiName + " from eventhub");
    }
    LocalEntryDTO localEntryDTO = new LocalEntryDTO();
    localEntryDTO.localEntries(deployedLocalEntries);
    return Response.ok().entity(localEntryDTO).build();
}
Also used : LocalEntryDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.LocalEntryDTO)

Aggregations

File (java.io.File)23 IOException (java.io.IOException)18 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)18 ArrayList (java.util.ArrayList)17 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)16 Operation (io.swagger.v3.oas.annotations.Operation)15 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)15 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)15 Response (javax.ws.rs.core.Response)15 Artifact (org.wso2.carbon.application.deployer.config.Artifact)15 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 DeploymentException (org.apache.axis2.deployment.DeploymentException)11 CappFile (org.wso2.carbon.application.deployer.config.CappFile)11 Deployer (org.apache.axis2.deployment.Deployer)10 ArtifactSynchronizerException (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)10 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)10 InputStream (java.io.InputStream)9 FileInputStream (java.io.FileInputStream)7 APIRuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto)7 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7