Search in sources :

Example 1 with ModelMapper

use of org.modelmapper.ModelMapper in project pinot by linkedin.

the class GenericResultSetMapper method main.

public static void main(String[] args) throws Exception {
    ModelMapper mapper = new ModelMapper();
    Map<String, Object> result = new HashMap<>();
    //[{jobName=Test_Anomaly_Task, jobId=1, workerId=1, taskType=MONITOR, id=1, taskInfo=clob2: '{"jobExecutionId":1,"monitorType":"UPDATE","expireDaysAgo":0}', lastModified=2016-08-24 17:25:53.258, version=0, taskStartTime=1470356753227, status=RUNNING, taskEndTime=1471220753227}]
    result.put("jobName", "Test_Anomaly_Task");
    result.put("jobId", 1L);
    result.put("taskType", "MONITOR");
    result.put("id", 1L);
    result.put("taskInfo", "clob2: '{\"jobExecutionId\":1,\"monitorType\":\"UPDATE\",\"expireDaysAgo\":0}'");
    result.put("taskType", "MONITOR");
    result.put("lastModified", "2016-08-24 17:25:53.258");
    result.put("status", "RUNNING");
    result.put("lastModified", "2016-08-24 17:25:53.258");
    TaskDTO taskSpec1 = mapper.map(result, TaskDTO.class);
    System.out.println(taskSpec1);
    //INPUT 2
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("/tmp/map.out.1472093046128")));
    Map<String, Object> inputMap = (Map<String, Object>) ois.readObject();
    TaskDTO taskSpec2 = mapper.map(inputMap, TaskDTO.class);
    System.out.println(taskSpec2);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) File(java.io.File) BiMap(com.google.common.collect.BiMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) FileInputStream(java.io.FileInputStream) ModelMapper(org.modelmapper.ModelMapper) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with ModelMapper

use of org.modelmapper.ModelMapper in project useful-java-links by Vedenin.

the class ModelMapperHelloWorld method main.

public static void main(String[] args) {
    // init mapper
    PropertyMap<Source, Destination> orderMap = new PropertyMap<Source, Destination>() {

        protected void configure() {
            map().setText(source.getMessage());
        }
    };
    ModelMapper modelMapper = new ModelMapper();
    modelMapper.addMappings(orderMap);
    // convert
    Source source = new Source("Hello World!");
    Destination destObject = modelMapper.map(source, Destination.class);
    // print Hello World!
    destObject.print();
}
Also used : PropertyMap(org.modelmapper.PropertyMap) ModelMapper(org.modelmapper.ModelMapper)

Example 3 with ModelMapper

use of org.modelmapper.ModelMapper in project Settler by EmhyrVarEmreis.

the class CategoryService method getCategoriesWithValue.

public ResponseEntity<List<CategoryWithValueDTO>> getCategoriesWithValue(Long userId) {
    if (Objects.isNull(userId) || userId < 0) {
        userId = Security.currentUser().getId();
    }
    QCategory category = QCategory.category;
    QTransaction transaction = QTransaction.transaction;
    List<Tuple> fetch = new JPAQuery<>(entityManager).from(category, transaction).select(category, transaction.value.sum()).where(transaction.creator.id.eq(userId)).where(transaction.categories.contains(category)).groupBy(category.code, category.description).orderBy(transaction.value.sum().desc()).fetch();
    ModelMapper preparedModelMapper = getModelMapper();
    List<CategoryWithValueDTO> categoryWithValueDTOList = new ArrayList<>(fetch.size());
    for (Tuple tuple : fetch) {
        Category c = tuple.get(category);
        Double d = tuple.get(transaction.value.sum());
        if (Objects.nonNull(c)) {
            categoryWithValueDTOList.add(new CategoryWithValueDTO(userId, preparedModelMapper.map(c, CategoryDTO.class), d));
        }
    }
    return new ResponseEntity<>(categoryWithValueDTOList, HttpStatus.OK);
}
Also used : QTransaction(pl.morecraft.dev.settler.domain.QTransaction) ResponseEntity(org.springframework.http.ResponseEntity) Category(pl.morecraft.dev.settler.domain.Category) QCategory(pl.morecraft.dev.settler.domain.QCategory) ArrayList(java.util.ArrayList) CategoryWithValueDTO(pl.morecraft.dev.settler.web.dto.CategoryWithValueDTO) QCategory(pl.morecraft.dev.settler.domain.QCategory) Tuple(com.querydsl.core.Tuple) ModelMapper(org.modelmapper.ModelMapper)

Example 4 with ModelMapper

use of org.modelmapper.ModelMapper in project Internet-Software-Architectures by zivko11.

the class ActorPerformancesManager method Create.

public boolean Create(ActorPerformancesDTO dto) {
    ModelMapper mapper = new ModelMapper();
    Actorperformances actorPerformances;
    try {
        actorPerformances = mapper.map(dto, Actorperformances.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return false;
    }
    actorPerformancesRepository.save(actorPerformances);
    return true;
}
Also used : Actorperformances(com.management.entities.Actorperformances) ModelMapper(org.modelmapper.ModelMapper)

Example 5 with ModelMapper

use of org.modelmapper.ModelMapper in project Internet-Software-Architectures by zivko11.

the class CinemaTheatreManager method ReadAll.

public ArrayList<CinemaTheatreDTO> ReadAll() {
    ModelMapper mapper = new ModelMapper();
    ArrayList<CinemaTheatre> listEntities = (ArrayList<CinemaTheatre>) cinemaTheatreRepository.findAll();
    ArrayList<CinemaTheatreDTO> listDTO = new ArrayList<CinemaTheatreDTO>();
    for (CinemaTheatre tmp : listEntities) {
        try {
            CinemaTheatreDTO dto = mapper.map(tmp, CinemaTheatreDTO.class);
            listDTO.add(dto);
        } catch (Exception exc) {
            exc.printStackTrace();
            return null;
        }
    }
    return listDTO;
}
Also used : ArrayList(java.util.ArrayList) CinemaTheatreDTO(com.management.dto.CinemaTheatreDTO) CinemaTheatre(com.management.entities.CinemaTheatre) ModelMapper(org.modelmapper.ModelMapper)

Aggregations

ModelMapper (org.modelmapper.ModelMapper)77 ArrayList (java.util.ArrayList)15 Date (java.util.Date)5 Actor (com.management.entities.Actor)4 CinemaTheatre (com.management.entities.CinemaTheatre)4 Event (com.management.entities.Event)4 Hall (com.management.entities.Hall)4 Performance (com.management.entities.Performance)4 Props (com.management.entities.Props)4 Seat (com.management.entities.Seat)4 User (com.management.entities.User)4 Actorperformances (com.management.entities.Actorperformances)3 FanZone (com.management.entities.FanZone)3 Friendslist (com.management.entities.Friendslist)3 History (com.management.entities.History)3 OmcOrder (com.paascloud.provider.model.domain.OmcOrder)3 UacUserToken (com.paascloud.provider.model.domain.UacUserToken)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SimpleExportXmEntityDto (com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto)2 ActorDTO (com.management.dto.ActorDTO)2