/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beans.directory.danger;
import beans.directory.danger.entity.DangerService;
import beans.directory.service.entity.Service;
import beans.directory.simple.entities.Speciality;
import framework.generic.ClipsServerException;
import java.util.ArrayList;
import framework.beans.SecuredBean;
import java.util.HashMap;
import java.util.List;
import javax.ejb.Stateless;
/**
* Security - Ok.
* @author axe
*/
@Stateless(mappedName="clips-beans/TempMapperBean")
public class TempMapperBean extends SecuredBean
implements TempMapperBeanRemote {
public TempMapperBean() {
super();
}
@Override
public ArrayList<TempMapperChunk> getTempMapperList() throws ClipsServerException {
//МАП ServiceID, TempMapperChunk
HashMap<Integer,TempMapperChunk> map = new HashMap<Integer, TempMapperChunk>();
List<DangerService> list = findEntityList(DangerService.class);
for (int i = 0; i < list.size(); i++) {
DangerService ds = list.get(i);
TempMapperChunk chunk = new TempMapperChunk();
chunk.service1ID = ds.getService().getId();
chunk.service2ID = ds.getService().getId();
chunk.specialityID = 0;
map.put(ds.getService().getId(), chunk);
}
return new ArrayList<TempMapperChunk>(map.values());
}
@Override
public void update(ArrayList<TempMapperChunk> chunkList) throws ClipsServerException {
for (int i = 0; i < chunkList.size(); i++) {
TempMapperChunk c = chunkList.get(i);
List<DangerService> list = findEntityList(DangerService.class, "service.id", c.service1ID);
for (int j = 0; j < list.size(); j++) {
DangerService dangerService = list.get(j);
dangerService.setService(findEntity(Service.class, c.service2ID));
if (c.specialityID == 0) {
dangerService.setSpeciality(null);
} else {
dangerService.setSpeciality(findEntity(Speciality.class, c.specialityID));
}
manager.persist(dangerService);
}
}
}
}