4 package com.edf.gde.services;
6 import com.edf.gde.ejb.MetadataEJB;
7 import com.edf.gde.ejb.PermissionsManagerEJB;
8 import com.edf.gde.ejb.UserEJB;
9 import com.edf.gde.tools.Credentials;
10 import com.edf.gde.transferables.AttributeGroupTO;
11 import com.edf.gde.transferables.AttributeTO;
12 import com.edf.gde.transferables.CommandTO;
13 import com.edf.gde.transferables.responses.CommandResultTO;
14 import java.util.logging.Logger;
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
23 public class AttributesService extends BaseService {
25 public static final String ServiceName = "AttributesService";
26 public static final int CREATEATTRIBUTE = 1;
27 public static final int DELETEATTRIBUTE = 2;
28 public static final int READATTRIBUTE = 3;
29 public static final int CREATEATTRIBUTEGROUP = 4;
30 public static final int DELETEATTRIBUTEGROUP = 5;
31 public static final int UPDATEATTRIBUTEGROUP = 6;
32 public static final int READATTRIBUTEGROUP = 7;
35 private UserEJB userEjb;
37 private PermissionsManagerEJB pm;
39 private MetadataEJB mjb;
42 public void processRequest(HttpServletRequest request, HttpServletResponse response) {
43 response.setContentType("text/html;charset=UTF-8");
44 Logger logger = Logger.getLogger(ServiceName);
45 CommandTO commandTO = getCommand(request);
46 CommandResultTO resultTO = new CommandResultTO();
47 Credentials credentials = getCredentials(request);
48 //userEjb.checkPassword(credentials.getLogin(), credentials.getPassword());
49 //pm.checkPermission(credentials.getLogin(), ServiceName, commandTO.getMethod());
51 switch (commandTO.getMethod()) {
52 case CREATEATTRIBUTE: {
53 AttributeTO ato = fromJson(commandTO.getData(), AttributeTO.class);
54 AttributeTO nato = mjb.createAttribute(ato);
55 resultTO.setData(toJson(nato));
58 case DELETEATTRIBUTE: {
59 long attributeId = commandTO.getLong("attributeId");
60 mjb.deleteAttribute(attributeId);
64 long attributeId = commandTO.getLong("attributeId");
65 AttributeTO ato = mjb.readAttribute(attributeId);
66 resultTO.setData(toJson(ato));
69 case CREATEATTRIBUTEGROUP: {
70 AttributeGroupTO agto = fromJson(commandTO.getData(), AttributeGroupTO.class);
71 AttributeGroupTO nagto = mjb.createAttributeGroup(agto);
72 resultTO.setData(toJson(nagto));
75 case DELETEATTRIBUTEGROUP: {
76 long attributeGroupId = commandTO.getLong("attributeGroupId");
77 mjb.deleteAttributeGroup(attributeGroupId);
80 case UPDATEATTRIBUTEGROUP: {
81 AttributeGroupTO agto = fromJson(commandTO.getData(), AttributeGroupTO.class);
82 AttributeGroupTO nagto = mjb.updateAttributeGroup(agto);
83 resultTO.setData(toJson(nagto));
86 case READATTRIBUTEGROUP: {
87 long id = commandTO.getLong("attributeGroupId");
88 AttributeGroupTO agto = mjb.readAttributeGroup(id);
89 resultTO.setData(toJson(agto));
94 } catch (RuntimeException ex) {
95 // Return error on any error...
96 resultTO.setCode(CommandResultTO.ERROR);
99 send(resultTO, response);