Search in sources :

Example 6 with LabelDTO

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

the class LabelMappingUtil method fromLabelArrayToListDTO.

/**
 * Converts an array of label model objects into REST API DTO objects.
 *
 * @param labelList An array of Label model objects
 * @return A List DTO of Label DTOs derived from the array of model objects
 */
public static LabelListDTO fromLabelArrayToListDTO(List<Label> labelList) {
    LabelListDTO listDTO = new LabelListDTO();
    List<LabelDTO> labelDTOList = new ArrayList<>();
    if (labelList != null) {
        for (Label label : labelList) {
            LabelDTO dto = fromLabelToDTO(label);
            labelDTOList.add(dto);
        }
    }
    listDTO.setCount(labelDTOList.size());
    listDTO.setList(labelDTOList);
    return listDTO;
}
Also used : ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) LabelDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO) LabelListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.LabelListDTO)

Example 7 with LabelDTO

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

the class MappingUtilTestCase method convertToLabelsTest.

@Test
public void convertToLabelsTest() {
    List<LabelDTO> labelDTOList = new ArrayList<>();
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    List<Label> labelList = MappingUtil.convertToLabels(labelDTOList);
    Assert.assertEquals(labelList.size(), labelDTOList.size());
    for (int i = 0; i < labelDTOList.size(); i++) {
        Assert.assertEquals(labelList.get(i).getName(), labelDTOList.get(i).getName());
        Assert.assertEquals(labelList.get(i).getAccessUrls(), labelDTOList.get(i).getAccessUrls());
    }
}
Also used : ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) LabelDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelDTO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Example 8 with LabelDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.LabelDTO 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)

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