Search in sources :

Example 6 with LabelListDTO

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

the class LabelsApiServiceImpl method labelsGet.

/**
 * Get all the labels.
 *
 * @param labelType       the type of the labels to be fetched
 * @param accept          Accept header value
 * @param ifNoneMatch     If-None-Match header value
 * @param ifModifiedSince If-Modified-Since header value
 * @param request         ms4j request object
 * @return Lable List
 * @throws NotFoundException If failed to get the label values
 */
@Override
public Response labelsGet(String labelType, String accept, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        List<Label> labels;
        if (labelType == null) {
            labels = RestAPIPublisherUtil.getApiPublisher(username).getAllLabels();
        } else {
            labels = RestAPIPublisherUtil.getApiPublisher(username).getLabelsByType(labelType);
        }
        LabelListDTO labelListDTO = MappingUtil.toLabelListDTO(labels);
        return Response.ok().entity(labelListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while retrieving Labels";
        HashMap<String, String> paramList = new HashMap<String, String>();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Label(org.wso2.carbon.apimgt.core.models.Label) LabelListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.LabelListDTO)

Example 7 with LabelListDTO

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

the class LabelMappingUtilTestCase method testToLabelListDTO.

@Test
public void testToLabelListDTO() {
    List<Label> labelList = new ArrayList<>();
    Label label1 = SampleTestObjectCreator.createLabel("label1").build();
    Label label2 = SampleTestObjectCreator.createLabel("label2").build();
    labelList.add(label1);
    labelList.add(label2);
    LabelListDTO labelListDTO = LabelMappingUtil.toLabelListDTO(labelList);
    assertEquals(labelListDTO.getCount(), (Integer) labelList.size());
    assertEquals(labelListDTO.getList().get(0).getName(), label1.getName());
    assertEquals(labelListDTO.getList().get(0).getAccessUrls(), label1.getAccessUrls());
    assertEquals(labelListDTO.getList().get(0).getLabelId(), label1.getId());
    assertEquals(labelListDTO.getList().get(1).getName(), label2.getName());
    assertEquals(labelListDTO.getList().get(1).getAccessUrls(), label2.getAccessUrls());
    assertEquals(labelListDTO.getList().get(1).getLabelId(), label2.getId());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.LabelListDTO) Test(org.testng.annotations.Test)

Example 8 with LabelListDTO

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

the class MappingUtil method toLabelDTO.

/**
 * Converts label List to LabelListDTO} List.
 *
 * @param labels list of labels
 * @return LabelDTO list
 */
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.publisher.dto.LabelDTO)

Example 9 with LabelListDTO

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

the class MappingUtil method toLabelListDTO.

/**
 * Convert list of Label to LabelListDTO
 *
 * @param labels List of labels
 * @return LabelListDTO list containing label data
 */
public static LabelListDTO toLabelListDTO(List<Label> labels) {
    LabelListDTO labelListDTO = new LabelListDTO();
    labelListDTO.setCount(labels.size());
    labelListDTO.setList(toLabelDTO(labels));
    return labelListDTO;
}
Also used : LabelListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.LabelListDTO)

Aggregations

Label (org.wso2.carbon.apimgt.core.models.Label)7 ArrayList (java.util.ArrayList)4 LabelListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.LabelListDTO)4 HashMap (java.util.HashMap)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 LabelListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.LabelListDTO)3 Test (org.testng.annotations.Test)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)2 ErrorHandler (org.wso2.carbon.apimgt.core.exception.ErrorHandler)1 LabelDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO)1 LabelListDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.LabelListDTO)1 LabelDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.LabelDTO)1