From 02454d2307d6d9eba7161185d9482667c3f5ba1a Mon Sep 17 00:00:00 2001 From: Bojnourdi Date: Fri, 14 Aug 2015 15:56:25 +0200 Subject: [PATCH] Working on Profiles Finished service implementation --- .../com/edf/gde/services/ProfileService.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 projects/GDE_App/GDE-war/src/java/com/edf/gde/services/ProfileService.java diff --git a/projects/GDE_App/GDE-war/src/java/com/edf/gde/services/ProfileService.java b/projects/GDE_App/GDE-war/src/java/com/edf/gde/services/ProfileService.java new file mode 100644 index 0000000..f357865 --- /dev/null +++ b/projects/GDE_App/GDE-war/src/java/com/edf/gde/services/ProfileService.java @@ -0,0 +1,96 @@ +/* + * (C) 2015 EDF + */ +package com.edf.gde.services; + +import com.edf.gde.ejb.PermissionsManagerEJB; +import com.edf.gde.ejb.ProfileEJB; +import com.edf.gde.ejb.UserEJB; +import com.edf.gde.tools.Credentials; +import com.edf.gde.transferables.CommandTO; +import com.edf.gde.transferables.ProfileAttributeTO; +import com.edf.gde.transferables.ProfileTO; +import com.edf.gde.transferables.responses.CommandResultTO; +import java.util.logging.Logger; +import javax.ejb.EJB; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Kavoos + */ +public class ProfileService extends BaseService { + + public static final String ServiceName = "AttributesService"; + public static final int CREATEPROFILE = 1; + public static final int DELETEPROFILE = 2; + public static final int READPROFILE = 3; + public static final int UPDATEPROFILE = 4; + public static final int CREATEPROFILEATTRIBUTE = 5; + public static final int DELETEPROFILEATTRIBUTE = 6; + public static final int READPROFILEATTRIBUTE = 7; + public static final int UPDATEPROFILEATTRIBUTE = 8; + + @EJB + private UserEJB userEjb; + @EJB + private PermissionsManagerEJB pm; + @EJB + private ProfileEJB pejb; + + @Override + public void processRequest(HttpServletRequest request, HttpServletResponse response) { + response.setContentType("text/html;charset=UTF-8"); + Logger logger = Logger.getLogger(ServiceName); + CommandTO commandTO = getCommand(request); + CommandResultTO resultTO = new CommandResultTO(); + Credentials credentials = getCredentials(request); + //userEjb.checkPassword(credentials.getLogin(), credentials.getPassword()); + //pm.checkPermission(credentials.getLogin(), ServiceName, commandTO.getMethod()); + try { + switch (commandTO.getMethod()) { + case CREATEPROFILE: { + ProfileTO profileTO = fromJson(commandTO.getData(), ProfileTO.class); + resultTO.setData(toJson(pejb.createProfile(profileTO))); + } + break; + case DELETEPROFILE: { + pejb.deleteProfile(commandTO.getLong("profileId")); + } + break; + case READPROFILE: { + resultTO.setData(toJson(pejb.readProfile(commandTO.getLong("profileId")))); + } + break; + case UPDATEPROFILE: { + resultTO.setData(toJson(pejb.updateProfile(fromJson(commandTO.getData(), ProfileTO.class)))); + } + break; + case CREATEPROFILEATTRIBUTE: { + resultTO.setData(toJson(pejb.createProfileAttribute(fromJson(commandTO.getData(), ProfileAttributeTO.class)))); + } + break; + case DELETEPROFILEATTRIBUTE: { + pejb.deleteProfileAttribute(commandTO.getLong("profileAttributeId")); + } + break; + case READPROFILEATTRIBUTE: { + resultTO.setData(toJson(pejb.readProfileAttribute(commandTO.getLong("profileAttributeId")))); + } + break; + case UPDATEPROFILEATTRIBUTE: { + resultTO.setData(toJson(pejb.updateProfileAttribute(fromJson(commandTO.getData(), ProfileAttributeTO.class)))); + } + } + } catch (RuntimeException ex) { + // Return error on any error... + resultTO.setCode(CommandResultTO.ERROR); + ex.printStackTrace(); + } finally { + send(resultTO, response); + } + + } + +} -- 2.39.2