Commit 5b81d8d3 authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade mapper para setear el parent a objecttype

parent 211da858
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
package es.redmic.es.maintenance.objects.mapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import es.redmic.es.maintenance.objects.service.ObjectTypeESService;
import es.redmic.models.es.common.utils.HierarchicalUtils;
import es.redmic.models.es.maintenance.objects.dto.ObjectTypeDTO;
import es.redmic.models.es.maintenance.objects.model.ObjectType;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MappingContext;

@Component
public class ObjectTypeESMapper extends CustomMapper<ObjectType, ObjectTypeDTO> {

	@Autowired
	ObjectTypeESService objectTypeESService;

	@Override
	public void mapAtoB(ObjectType a, ObjectTypeDTO b, MappingContext context) {

		String parent = HierarchicalUtils.getParentId(a.getPath());

		if (parent != null)
			b.setParent(objectTypeESService.get(parent));
	}
}