Search in sources :

Example 56 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class LifecycleModificationHandler method clearConfigCache.

private void clearConfigCache(RequestContext requestContext) {
    Resource resource = requestContext.getResource();
    if (resource instanceof ResourceImpl) {
        ResourceImpl resourceImpl = (ResourceImpl) resource;
        if (resourceImpl != null && APIConstants.API_LIFE_CYCLE.equals(resourceImpl.getName())) {
            Cache lcCache = Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER).getCache(APIConstants.LC_CACHE_NAME);
            String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
            String cacheName = tenantDomain + "_" + APIConstants.LC_CACHE_NAME;
            if (lcCache.containsKey(cacheName)) {
                lcCache.remove(cacheName);
                if (log.isDebugEnabled()) {
                    log.debug("Lifecycle cache cleared for tenant domain " + tenantDomain);
                }
            }
        }
    }
}
Also used : ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) Resource(org.wso2.carbon.registry.core.Resource) Cache(javax.cache.Cache)

Example 57 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method getAPILifecycleHistory.

/**
 * Retrieves API Lifecycle history information
 *
 * @param apiId API Id
 * @param ifNoneMatch If-None-Match header value
 * @return API Lifecycle history information
 */
@Override
public Response getAPILifecycleHistory(String apiId, String ifNoneMatch, MessageContext messageContext) {
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        API api;
        APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiId);
        if (apiRevision != null && apiRevision.getApiUUID() != null) {
            api = apiProvider.getAPIbyUUID(apiRevision.getApiUUID(), organization);
        } else {
            api = apiProvider.getAPIbyUUID(apiId, organization);
        }
        return Response.ok().entity(PublisherCommonUtils.getLifecycleHistoryDTO(api.getUuid(), apiProvider)).build();
    } catch (APIManagementException e) {
        // Auth failure occurs when cross tenant accessing APIs. Sends 404, since we don't need to expose the existence of the resource
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
        } else if (isAuthorizationFailure(e)) {
            RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving the lifecycle " + "events of API : " + apiId, e, log);
        } else {
            String errorMessage = "Error while retrieving the lifecycle events of API : " + apiId;
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    }
    return null;
}
Also used : APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 58 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method changeAPILifecycle.

@Override
public Response changeAPILifecycle(String action, String apiId, String lifecycleChecklist, String ifMatch, MessageContext messageContext) {
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        ApiTypeWrapper apiWrapper = new ApiTypeWrapper(apiProvider.getAPIbyUUID(apiId, organization));
        APIStateChangeResponse stateChangeResponse = PublisherCommonUtils.changeApiOrApiProductLifecycle(action, apiWrapper, lifecycleChecklist, organization);
        // returns the current lifecycle state
        // todo try to prevent this call
        LifecycleStateDTO stateDTO = getLifecycleState(apiId, organization);
        WorkflowResponseDTO workflowResponseDTO = APIMappingUtil.toWorkflowResponseDTO(stateDTO, stateChangeResponse);
        return Response.ok().entity(workflowResponseDTO).build();
    } catch (APIManagementException e) {
        // Auth failure occurs when cross tenant accessing APIs. Sends 404, since we don't need to expose the existence of the resource
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
        } else if (isAuthorizationFailure(e)) {
            RestApiUtil.handleAuthorizationFailure("Authorization failure while updating the lifecycle of API " + apiId, e, log);
        } else {
            RestApiUtil.handleInternalServerError("Error while updating lifecycle of API " + apiId, e, log);
        }
    }
    return null;
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO) LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 59 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class APIProviderImplTest method testChangeAPILCCheckListItems.

@Test
public void testChangeAPILCCheckListItems() throws APIManagementException, GovernanceException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
    GenericArtifact apiArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(APIUtil.getAPIArtifact(apiId, apiProvider.registry)).thenReturn(apiArtifact);
    Mockito.when(apiArtifact.isLCItemChecked(10, "APILifeCycle")).thenThrow(GovernanceException.class).thenReturn(false, true);
    String msg = "Error while setting registry lifecycle checklist items for the API: API1";
    try {
        apiProvider.changeAPILCCheckListItems(apiId, 10, true);
    } catch (APIManagementException e) {
        Assert.assertEquals(msg, e.getMessage());
    }
    // status checked
    assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
    // status false
    assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 60 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class APIMappingUtil method fromLifecycleHistoryModelToDTO.

/**
 * Return the REST API DTO representation of API Lifecycle history information.
 *
 * @param lifeCycleEvents API lifecycle history information
 * @return REST API DTO representation of API Lifecycle history information
 */
public static LifecycleHistoryDTO fromLifecycleHistoryModelToDTO(List<LifeCycleEvent> lifeCycleEvents) {
    LifecycleHistoryDTO historyDTO = new LifecycleHistoryDTO();
    historyDTO.setCount(lifeCycleEvents.size());
    for (LifeCycleEvent event : lifeCycleEvents) {
        LifecycleHistoryItemDTO historyItemDTO = new LifecycleHistoryItemDTO();
        historyItemDTO.setPostState(event.getNewStatus());
        historyItemDTO.setPreviousState(event.getOldStatus());
        historyItemDTO.setUser(event.getUserId());
        String updatedTime = RestApiCommonUtil.getRFC3339Date(event.getDate());
        historyItemDTO.setUpdatedTime(updatedTime);
        historyDTO.getList().add(historyItemDTO);
    }
    return historyDTO;
}
Also used : LifecycleHistoryDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleHistoryDTO) LifecycleHistoryItemDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleHistoryItemDTO) LifeCycleEvent(org.wso2.carbon.apimgt.api.model.LifeCycleEvent)

Aggregations

Test (org.testng.annotations.Test)20 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)20 API (org.wso2.carbon.apimgt.core.models.API)20 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)19 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)10 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)10 LifecycleException (org.wso2.carbon.lcm.core.exception.LifecycleException)10 JSONObject (org.json.simple.JSONObject)8 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)8 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)7 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7 List (java.util.List)6 IOException (java.io.IOException)5 Map (java.util.Map)5 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)4