de.terrestris.shoguncore.service.MapService Maven / Gradle / Ivy
package de.terrestris.shoguncore.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import de.terrestris.shoguncore.dao.LayerDao;
import de.terrestris.shoguncore.dao.MapDao;
import de.terrestris.shoguncore.model.PersistentObject;
import de.terrestris.shoguncore.model.layer.Layer;
import de.terrestris.shoguncore.model.module.Map;
import de.terrestris.shoguncore.model.module.Module;
/**
* Service class for the {@link Module} model.
*
* @author Nils Bühner
* @see AbstractCrudService
*/
@Service("mapService")
public class MapService> extends
ModuleService {
@Autowired
@Qualifier("layerService")
private LayerService> layerService;
/**
* Default constructor, which calls the type-constructor
*/
@SuppressWarnings("unchecked")
public MapService() {
this((Class) Map.class);
}
/**
* Constructor that sets the concrete entity class for the service.
* Subclasses MUST call this constructor.
*/
protected MapService(Class entityClass) {
super(entityClass);
}
/**
* We have to use {@link Qualifier} to define the correct dao here.
* Otherwise, spring can not decide which dao has to be autowired here
* as there are multiple candidates.
*/
@Override
@Autowired
@Qualifier("mapDao")
public void setDao(D dao) {
this.dao = dao;
}
/**
*
*/
@PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#layer, 'READ')")
@Transactional(readOnly = true)
public Set findMapsWithLayer(Layer layer) {
return dao.findMapsWithLayer(layer);
}
/**
* TODO secure this method!?
*
* @param layerIds
* @throws Exception
*/
@SuppressWarnings("unchecked")
@PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#mapModuleId, 'de.terrestris.shoguncore.model.module.Map', 'UPDATE')")
public List setLayersForMap(Integer mapModuleId, List layerIds) throws Exception {
E module = this.findById(mapModuleId);
List layers = new ArrayList();
if (module instanceof Map) {
Map mapModule = (Map) module;
for (Integer id : layerIds) {
PersistentObject entity = this.layerService.findById(id);
if (entity instanceof Layer) {
Layer layer = (Layer) entity;
if (layer != null) {
layers.add(layer);
}
}
}
mapModule.setMapLayers(layers);
this.saveOrUpdate((E) mapModule);
return layers;
} else {
throw new Exception("Can't find mapModule with id " + mapModuleId.toString());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy