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);
}
}
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);
}
}
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;
}
Aggregations