Search in sources :

Example 1 with LabelDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO in project carbon-apimgt by wso2.

the class LabelMappingUtil method fromLabelToDTO.

/**
 * Converts a single Label model object into DTO object.
 *
 * @param label Label  model object
 * @return DTO object derived from the label model object
 */
public static LabelDTO fromLabelToDTO(Label label) {
    LabelDTO labelDTO = new LabelDTO();
    labelDTO.accessUrls(label.getAccessUrls());
    labelDTO.description(label.getDescription());
    labelDTO.setName(label.getName());
    labelDTO.labelUUID(label.getId());
    labelDTO.setType(label.getType());
    return labelDTO;
}
Also used : LabelDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO)

Example 2 with LabelDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createUniqueLabelDTO.

/**
 * Create a sample unique LabelDTO object.
 *
 * @return LabelDTO object
 */
protected static LabelDTO createUniqueLabelDTO() {
    LabelDTO labelDTO = new LabelDTO();
    labelDTO.setName(UUID.randomUUID().toString());
    List<String> accessURLs = new ArrayList<>();
    accessURLs.add(UUID.randomUUID().toString());
    accessURLs.add(UUID.randomUUID().toString());
    accessURLs.add(UUID.randomUUID().toString());
    labelDTO.setAccessUrls(accessURLs);
    return labelDTO;
}
Also used : ArrayList(java.util.ArrayList) LabelDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelDTO)

Example 3 with LabelDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO in project carbon-apimgt by wso2.

the class LabelMappingUtil method toLabelDTO.

/**
 * Converts labels to list of LabelDTO
 *
 * @param labels List of Labels
 * @return List of LabelDTOs
 */
private static List<LabelDTO> toLabelDTO(List<Label> labels) {
    List<LabelDTO> labelDTOs = new ArrayList<>();
    for (Label label : labels) {
        LabelDTO labelDTO = new LabelDTO();
        labelDTO.setLabelId(label.getId());
        labelDTO.setName(label.getName());
        labelDTO.setAccessUrls(label.getAccessUrls());
        labelDTOs.add(labelDTO);
    }
    return labelDTOs;
}
Also used : ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) LabelDTO(org.wso2.carbon.apimgt.rest.api.store.dto.LabelDTO)

Example 4 with LabelDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO in project carbon-apimgt by wso2.

the class MappingUtil method convertToLabels.

/**
 * Converts labelDTOs into labels
 *
 * @param labelDTOs List of LabelDTOs
 * @return List of Labels
 */
public static List<Label> convertToLabels(List<LabelDTO> labelDTOs) {
    List<Label> labels = new ArrayList<>();
    for (LabelDTO labelDTO : labelDTOs) {
        String labelId = UUID.randomUUID().toString();
        Label label = new Label.Builder().id(labelId).name(labelDTO.getName()).accessUrls(labelDTO.getAccessUrls()).build();
        labels.add(label);
    }
    return labels;
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelDTO)

Example 5 with LabelDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO in project carbon-apimgt by wso2.

the class LabelsApiServiceImpl method labelsLabelIdPut.

/**
 *  Update the label
 * @param body     The body of the label with fields to be modified
 * @param contentType The content type of the body
 * @param request     The ms4j request object
 * @return  200 OK response.
 * @throws NotFoundException
 */
@Override
public Response labelsLabelIdPut(String labelId, LabelDTO body, String contentType, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        body.labelUUID(labelId);
        Label updatedLabel = apiMgtAdminService.updateLabel(LabelMappingUtil.fromDTOTLabel(body));
        return Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelToDTO(updatedLabel)).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while adding label, label name: " + body.getName();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Label(org.wso2.carbon.apimgt.core.models.Label)

Aggregations

ArrayList (java.util.ArrayList)6 Label (org.wso2.carbon.apimgt.core.models.Label)6 LabelDTO (org.wso2.carbon.apimgt.rest.api.core.dto.LabelDTO)3 LabelDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO)2 Test (org.testng.annotations.Test)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)1 LabelListDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.LabelListDTO)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1 LabelDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.LabelDTO)1 LabelDTO (org.wso2.carbon.apimgt.rest.api.store.dto.LabelDTO)1