Search in sources :

Example 6 with CheckListItem

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem in project carbon-apimgt by wso2.

the class PublisherCommonUtils method changeApiOrApiProductLifecycle.

/**
 * Change the lifecycle state of an API or API Product identified by UUID
 *
 * @param action       LC state change action
 * @param apiTypeWrapper API Type Wrapper (API or API Product)
 * @param lcChecklist  LC state change check list
 * @param organization Organization of logged-in user
 * @return APIStateChangeResponse
 * @throws APIManagementException Exception if there is an error when changing the LC state of API or API Product
 */
public static APIStateChangeResponse changeApiOrApiProductLifecycle(String action, ApiTypeWrapper apiTypeWrapper, String lcChecklist, String organization) throws APIManagementException {
    String[] checkListItems = lcChecklist != null ? lcChecklist.split(APIConstants.DELEM_COMMA) : new String[0];
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    Map<String, Object> apiLCData = apiProvider.getAPILifeCycleData(apiTypeWrapper.getUuid(), organization);
    String[] nextAllowedStates = (String[]) apiLCData.get(APIConstants.LC_NEXT_STATES);
    if (!ArrayUtils.contains(nextAllowedStates, action)) {
        throw new APIManagementException("Action '" + action + "' is not allowed. Allowed actions are " + Arrays.toString(nextAllowedStates), ExceptionCodes.from(ExceptionCodes.UNSUPPORTED_LIFECYCLE_ACTION, action));
    }
    // check and set lifecycle check list items including "Deprecate Old Versions" and "Require Re-Subscription".
    Map<String, Boolean> lcMap = new HashMap<>();
    for (String checkListItem : checkListItems) {
        String[] attributeValPair = checkListItem.split(APIConstants.DELEM_COLON);
        if (attributeValPair.length == 2) {
            String checkListItemName = attributeValPair[0].trim();
            boolean checkListItemValue = Boolean.parseBoolean(attributeValPair[1].trim());
            lcMap.put(checkListItemName, checkListItemValue);
        }
    }
    try {
        return apiProvider.changeLifeCycleStatus(organization, apiTypeWrapper, action, lcMap);
    } catch (FaultGatewaysException e) {
        throw new APIManagementException("Error while change the state of artifact with name - " + apiTypeWrapper.getName(), e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) JSONObject(org.json.simple.JSONObject) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 7 with CheckListItem

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem in project carbon-apimgt by wso2.

the class APIPublisherImpl method updateCheckListItem.

/**
 * This method used to Update the lifecycle checklist of API
 *
 * @param apiId            UUID of the API
 * @param status           Current API lifecycle status.
 * @param checkListItemMap Check list item values.
 * @throws APIManagementException If failed to update checklist item values.
 */
@Override
public void updateCheckListItem(String apiId, String status, Map<String, Boolean> checkListItemMap) throws APIManagementException {
    API api = getApiDAO().getAPI(apiId);
    try {
        API.APIBuilder apiBuilder = new API.APIBuilder(api);
        apiBuilder.lastUpdatedTime(LocalDateTime.now());
        apiBuilder.updatedBy(getUsername());
        apiBuilder.lifecycleState(getApiLifecycleManager().getLifecycleDataForState(apiBuilder.getLifecycleInstanceId(), apiBuilder.getLifeCycleStatus()));
        for (Map.Entry<String, Boolean> checkListItem : checkListItemMap.entrySet()) {
            getApiLifecycleManager().checkListItemEvent(api.getLifecycleInstanceId(), api.getLifeCycleStatus(), checkListItem.getKey(), checkListItem.getValue());
        }
    } catch (LifecycleException e) {
        String errorMsg = "Couldn't get the lifecycle status of api ID " + apiId;
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, ExceptionCodes.APIMGT_LIFECYCLE_EXCEPTION);
    }
}
Also used : LifecycleException(org.wso2.carbon.lcm.core.exception.LifecycleException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) API(org.wso2.carbon.apimgt.core.models.API) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with CheckListItem

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem in project carbon-apimgt by wso2.

the class APIProviderImpl method checkAndChangeAPILCCheckListItem.

/**
 * This method is to set a lifecycle check list item given the APIIdentifier and the checklist item name.
 * If the given item not in the allowed lifecycle check items list or item is already checked, this will stay
 * silent and return false. Otherwise, the checklist item will be updated and returns true.
 *
 * @param apiIdentifier  APIIdentifier
 * @param checkItemName  Name of the checklist item
 * @param checkItemValue Value to be set to the checklist item
 * @return boolean value representing success not not
 * @throws APIManagementException
 */
@Override
public boolean checkAndChangeAPILCCheckListItem(APIIdentifier apiIdentifier, String checkItemName, boolean checkItemValue) throws APIManagementException {
    Map<String, Object> lifeCycleData = getAPILifeCycleData(apiIdentifier);
    if (lifeCycleData != null && lifeCycleData.get(APIConstants.LC_CHECK_ITEMS) != null && lifeCycleData.get(APIConstants.LC_CHECK_ITEMS) instanceof ArrayList) {
        List checkListItems = (List) lifeCycleData.get(APIConstants.LC_CHECK_ITEMS);
        for (Object item : checkListItems) {
            if (item instanceof CheckListItem) {
                CheckListItem checkListItem = (CheckListItem) item;
                int index = Integer.parseInt(checkListItem.getOrder());
                if (checkListItem.getName().equals(checkItemName)) {
                    changeAPILCCheckListItems(apiIdentifier, index, checkItemValue);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : CheckListItem(org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

JSONObject (org.json.simple.JSONObject)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 CheckListItem (org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem)5 List (java.util.List)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)2 AsyncSpecPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.AsyncSpecPersistenceException)2 DocumentationPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)2 GraphQLPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.GraphQLPersistenceException)2 MediationPolicyPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.MediationPolicyPersistenceException)2 OASPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException)2 PersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException)2 ThumbnailPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.ThumbnailPersistenceException)2 WSDLPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.WSDLPersistenceException)2 LifecycleBean (org.wso2.carbon.governance.custom.lifecycles.checklist.beans.LifecycleBean)2