use of org.wso2.carbon.apimgt.rest.api.core.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;
}
use of org.wso2.carbon.apimgt.rest.api.core.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;
}
use of org.wso2.carbon.apimgt.rest.api.core.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;
}
use of org.wso2.carbon.apimgt.rest.api.core.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;
}
use of org.wso2.carbon.apimgt.rest.api.core.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();
}
}
Aggregations