Search in sources :

Example 1 with LifecycleStateAvailableTransitionsDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateAvailableTransitionsDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromLifecycleModelToDTO.

/**
 * Return the REST API DTO representation of API Lifecycle state information.
 *
 * @param apiLCData API lifecycle state information
 * @return REST API DTO representation of API Lifecycle state information
 */
public static LifecycleStateDTO fromLifecycleModelToDTO(Map<String, Object> apiLCData, boolean apiOlderVersionExist) {
    LifecycleStateDTO lifecycleStateDTO = new LifecycleStateDTO();
    String currentState = (String) apiLCData.get(APIConstants.LC_STATUS);
    lifecycleStateDTO.setState(currentState);
    String[] nextStates = (String[]) apiLCData.get(APIConstants.LC_NEXT_STATES);
    if (nextStates != null) {
        List<LifecycleStateAvailableTransitionsDTO> transitionDTOList = new ArrayList<>();
        for (String state : nextStates) {
            LifecycleStateAvailableTransitionsDTO transitionDTO = new LifecycleStateAvailableTransitionsDTO();
            transitionDTO.setEvent(state);
            // todo: Set target state properly
            transitionDTO.setTargetState("");
            transitionDTOList.add(transitionDTO);
        }
        lifecycleStateDTO.setAvailableTransitions(transitionDTOList);
    }
    List checkListItems = (List) apiLCData.get(APIConstants.LC_CHECK_ITEMS);
    if (checkListItems != null) {
        List<LifecycleStateCheckItemsDTO> checkItemsDTOList = new ArrayList<>();
        for (Object checkListItemObj : checkListItems) {
            CheckListItem checkListItem = (CheckListItem) checkListItemObj;
            if (!apiOlderVersionExist && (checkListItem.getName().equals(APIConstants.DEPRECATE_CHECK_LIST_ITEM) || checkListItem.getName().equals(APIConstants.RESUBSCRIBE_CHECK_LIST_ITEM))) {
                continue;
            }
            LifecycleStateCheckItemsDTO checkItemsDTO = new LifecycleStateCheckItemsDTO();
            checkItemsDTO.setName(checkListItem.getName());
            checkItemsDTO.setValue(Boolean.getBoolean(checkListItem.getValue()));
            // todo: Set targets properly
            checkItemsDTO.setRequiredStates(new ArrayList<>());
            checkItemsDTOList.add(checkItemsDTO);
        }
        lifecycleStateDTO.setCheckItems(checkItemsDTOList);
    }
    return lifecycleStateDTO;
}
Also used : LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) LifecycleStateAvailableTransitionsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateAvailableTransitionsDTO) CheckListItem(org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem) ArrayList(java.util.ArrayList) LifecycleStateCheckItemsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateCheckItemsDTO) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.simple.JSONObject)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 JSONObject (org.json.simple.JSONObject)1 LifecycleStateAvailableTransitionsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateAvailableTransitionsDTO)1 LifecycleStateCheckItemsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateCheckItemsDTO)1 LifecycleStateDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO)1 CheckListItem (org.wso2.carbon.governance.custom.lifecycles.checklist.util.CheckListItem)1