rsanchez
2014-12-12 4c13c7324a920f5cca9601154e5224e5d7484fa9
#2140 fix - Many changes related with cahce and JPA cycling
relationships
15 files modified
changed files
securis/src/main/java/net/curisit/securis/db/Application.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/LicenseType.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/LicenseTypeMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Organization.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/BasicServices.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/PackResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/UserResource.java patch | view | blame | history
securis/src/main/resources/META-INF/persistence.xml patch | view | blame | history
securis/src/main/webapp/js/admin.js patch | view | blame | history
securis/src/main/webapp/js/catalogs.js patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Application.java
....@@ -22,6 +22,7 @@
2222 import com.fasterxml.jackson.annotation.JsonIgnore;
2323 import com.fasterxml.jackson.annotation.JsonInclude;
2424 import com.fasterxml.jackson.annotation.JsonInclude.Include;
25
+import com.fasterxml.jackson.annotation.JsonManagedReference;
2526 import com.fasterxml.jackson.annotation.JsonProperty;
2627
2728 /**
....@@ -56,13 +57,14 @@
5657 @JsonProperty("creation_timestamp")
5758 private Date creationTimestamp;
5859
59
- @JsonIgnore
6060 // We don't include the referenced entities to limit the size of each row at
61
- // the listing
61
+ // // the listing
62
+ @JsonIgnore
6263 @OneToMany(fetch = FetchType.LAZY, mappedBy = "application")
6364 private Set<LicenseType> licenseTypes;
6465
6566 @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "application")
67
+ @JsonManagedReference
6668 private Set<ApplicationMetadata> metadata;
6769
6870 public Integer getId() {
....@@ -90,7 +92,6 @@
9092 }
9193
9294 public Date getCreationTimestamp() {
93
- LOG.info("APP {} TS: {}", this.id, this.creationTimestamp);
9495 return creationTimestamp;
9596 }
9697
....@@ -98,16 +99,9 @@
9899 this.creationTimestamp = creationTimestamp;
99100 }
100101
101
- public Set<LicenseType> getLicenseTypes() {
102
- return licenseTypes;
103
- }
104
-
105
- public void setLicenseTypes(Set<LicenseType> licenseTypes) {
106
- this.licenseTypes = licenseTypes;
107
- }
108
-
109102 @JsonProperty("metadata")
110103 public Set<ApplicationMetadata> getApplicationMetadata() {
104
+ LOG.info("Getting metadata from app: {}", metadata);
111105 return metadata;
112106 }
113107
....@@ -137,4 +131,13 @@
137131 public void setLicenseFilename(String licenseFilename) {
138132 this.licenseFilename = licenseFilename;
139133 }
134
+
135
+ public Set<LicenseType> getLicenseTypes() {
136
+ LOG.info("Getting list license types!!!!");
137
+ return licenseTypes;
138
+ }
139
+
140
+ public void setLicenseTypes(Set<LicenseType> licenseTypes) {
141
+ this.licenseTypes = licenseTypes;
142
+ }
140143 }
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java
....@@ -16,7 +16,7 @@
1616 import org.apache.logging.log4j.Logger;
1717
1818 import com.fasterxml.jackson.annotation.JsonAutoDetect;
19
-import com.fasterxml.jackson.annotation.JsonIgnore;
19
+import com.fasterxml.jackson.annotation.JsonBackReference;
2020 import com.fasterxml.jackson.annotation.JsonInclude;
2121 import com.fasterxml.jackson.annotation.JsonInclude.Include;
2222 import com.fasterxml.jackson.annotation.JsonProperty;
....@@ -38,10 +38,10 @@
3838
3939 private static final long serialVersionUID = 1L;
4040
41
- @JsonIgnore
4241 @Id
4342 @ManyToOne
4443 @JoinColumn(name = "application_id")
44
+ @JsonBackReference
4545 private Application application;
4646
4747 @Id
....@@ -65,6 +65,7 @@
6565 }
6666
6767 public Application getApplication() {
68
+ LOG.info("Getting application from app metadata: {}", application);
6869 return application;
6970 }
7071
....@@ -73,27 +74,11 @@
7374 }
7475
7576 public Date getCreationTimestamp() {
76
- LOG.info("APP_MD (app: {}) {} TS: {}", this.application.getId(), this.key, this.creationTimestamp);
7777 return creationTimestamp;
7878 }
7979
8080 public void setCreationTimestamp(Date creationTimestamp) {
8181 this.creationTimestamp = creationTimestamp;
82
- }
83
-
84
- @JsonProperty("application_id")
85
- public Integer getApplicationId() {
86
- return application == null ? null : application.getId();
87
- }
88
-
89
- @JsonProperty("application_id")
90
- public void setApplicationId(Integer idApplication) {
91
- if (idApplication == null) {
92
- application = null;
93
- } else {
94
- application = new Application();
95
- application.setId(idApplication);
96
- }
9782 }
9883
9984 public String getValue() {
....@@ -129,7 +114,7 @@
129114 @Override
130115 public String toString() {
131116
132
- return String.format("ApplicationMetadata (%s - %s)", this.application == null ? null : application.getId(), this.key);
117
+ return String.format("ApplicationMetadata (%s)", this.key);
133118 }
134119
135120 }
securis/src/main/java/net/curisit/securis/db/LicenseType.java
....@@ -25,6 +25,7 @@
2525 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2626 import com.fasterxml.jackson.annotation.JsonInclude;
2727 import com.fasterxml.jackson.annotation.JsonInclude.Include;
28
+import com.fasterxml.jackson.annotation.JsonManagedReference;
2829 import com.fasterxml.jackson.annotation.JsonProperty;
2930
3031 /**
....@@ -59,11 +60,12 @@
5960 private Date creationTimestamp;
6061
6162 @JsonIgnore
62
- @ManyToOne
63
+ @ManyToOne(fetch = FetchType.LAZY)
6364 @JoinColumn(name = "application_id")
6465 private Application application;
6566
6667 @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "licenseType")
68
+ @JsonManagedReference
6769 private Set<LicenseTypeMetadata> metadata;
6870
6971 public Set<LicenseTypeMetadata> getMetadata() {
....@@ -107,6 +109,7 @@
107109 }
108110
109111 public Application getApplication() {
112
+ LOG.info("Getting APP from LicType");
110113 return application;
111114 }
112115
securis/src/main/java/net/curisit/securis/db/LicenseTypeMetadata.java
....@@ -12,10 +12,10 @@
1212 import javax.persistence.Table;
1313
1414 import com.fasterxml.jackson.annotation.JsonAutoDetect;
15
+import com.fasterxml.jackson.annotation.JsonBackReference;
1516 import com.fasterxml.jackson.annotation.JsonIgnore;
1617 import com.fasterxml.jackson.annotation.JsonInclude;
1718 import com.fasterxml.jackson.annotation.JsonInclude.Include;
18
-import com.fasterxml.jackson.annotation.JsonProperty;
1919
2020 /**
2121 * Entity implementation class for Entity: licensetype_metadata
....@@ -32,10 +32,11 @@
3232
3333 private static final long serialVersionUID = 1L;
3434
35
- @Id
3635 @JsonIgnore
36
+ @Id
3737 @ManyToOne
3838 @JoinColumn(name = "license_type_id")
39
+ @JsonBackReference
3940 private LicenseType licenseType;
4041
4142 @Id
....@@ -45,21 +46,6 @@
4546 private String value;
4647
4748 private boolean mandatory;
48
-
49
- @JsonProperty("licensetype_id")
50
- public Integer getLicenseTypeId() {
51
- return licenseType == null ? null : licenseType.getId();
52
- }
53
-
54
- @JsonProperty("licensetype_id")
55
- public void setLicenseTypeId(Integer idLicenseType) {
56
- if (idLicenseType == null) {
57
- licenseType = null;
58
- } else {
59
- licenseType = new LicenseType();
60
- licenseType.setId(idLicenseType);
61
- }
62
- }
6349
6450 public LicenseType getLicenseType() {
6551 return licenseType;
securis/src/main/java/net/curisit/securis/db/Organization.java
....@@ -1,8 +1,8 @@
11 package net.curisit.securis.db;
22
33 import java.io.Serializable;
4
-import java.util.ArrayList;
54 import java.util.Date;
5
+import java.util.HashSet;
66 import java.util.List;
77 import java.util.Set;
88
....@@ -72,7 +72,7 @@
7272 inverseJoinColumns = {
7373 @JoinColumn(name = "username", referencedColumnName = "username")
7474 })
75
- private List<User> users;
75
+ private Set<User> users;
7676
7777 @JsonIgnore
7878 // We don't include the users to limit the size of each row a the listing
....@@ -125,11 +125,11 @@
125125 this.creationTimestamp = creationTimestamp;
126126 }
127127
128
- public List<User> getUsers() {
128
+ public Set<User> getUsers() {
129129 return users;
130130 }
131131
132
- public void setUsers(List<User> users) {
132
+ public void setUsers(Set<User> users) {
133133 this.users = users;
134134 }
135135
....@@ -166,7 +166,7 @@
166166
167167 @JsonProperty("users_ids")
168168 public void setUsersIds(List<String> usersIds) {
169
- users = new ArrayList<>();
169
+ users = new HashSet<>();
170170 if (usersIds != null) {
171171 for (String userid : usersIds) {
172172 User u = new User();
....@@ -177,11 +177,11 @@
177177 }
178178
179179 @JsonProperty("users_ids")
180
- public List<String> getUsersIds() {
180
+ public Set<String> getUsersIds() {
181181 if (users == null) {
182182 return null;
183183 }
184
- List<String> ids = new ArrayList<>();
184
+ Set<String> ids = new HashSet<>();
185185 for (User user : users) {
186186 ids.add(user.getUsername());
187187 }
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
....@@ -26,10 +26,14 @@
2626
2727 import net.curisit.integrity.commons.Utils;
2828 import net.curisit.securis.DefaultExceptionHandler;
29
+import net.curisit.securis.SeCurisException;
2930 import net.curisit.securis.db.Application;
3031 import net.curisit.securis.db.ApplicationMetadata;
3132 import net.curisit.securis.security.BasicSecurityContext;
3233 import net.curisit.securis.security.Securable;
34
+import net.curisit.securis.services.exception.SeCurisServiceException;
35
+import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes;
36
+import net.curisit.securis.utils.JsonUtils;
3337 import net.curisit.securis.utils.TokenHelper;
3438
3539 import org.apache.logging.log4j.LogManager;
....@@ -71,6 +75,7 @@
7175 LOG.info("Getting applications list ");
7276
7377 EntityManager em = emProvider.get();
78
+ em.clear();
7479 TypedQuery<Application> q = em.createNamedQuery("list-applications", Application.class);
7580 List<Application> list = q.getResultList();
7681
....@@ -80,6 +85,7 @@
8085 /**
8186 *
8287 * @return the server version in format majorVersion.minorVersion
88
+ * @throws SeCurisServiceException
8389 */
8490 @GET
8591 @Path("/{appid}")
....@@ -87,7 +93,7 @@
8793 MediaType.APPLICATION_JSON
8894 })
8995 @Securable
90
- public Response get(@PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
96
+ public Response get(@PathParam("appid") String appid) throws SeCurisServiceException {
9197 LOG.info("Getting application data for id: {}: ", appid);
9298 if (appid == null || "".equals(appid)) {
9399 LOG.error("Application ID is mandatory");
....@@ -95,12 +101,28 @@
95101 }
96102
97103 EntityManager em = emProvider.get();
98
- Application app = em.find(Application.class, Integer.parseInt(appid));
104
+ em.clear();
105
+
106
+ Application app = null;
107
+ try {
108
+ LOG.info("READY to GET app: {}", appid);
109
+ app = em.find(Application.class, Integer.parseInt(appid));
110
+ } catch (Exception e) {
111
+ LOG.info("ERROR GETTING app: {}", e);
112
+ }
99113 if (app == null) {
100114 LOG.error("Application with id {} not found in DB", appid);
115
+ throw new SeCurisServiceException(ErrorCodes.NOT_FOUND, "Application not found with ID: " + appid);
116
+ }
101117
102
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid)
103
- .build();
118
+ try {
119
+ LOG.info("JSON for APP:\n\n\n");
120
+ LOG.info(JsonUtils.toJSON(app));
121
+ } catch (SeCurisException e) {
122
+ LOG.info("ERROR {}", e);
123
+
124
+ } catch (Exception e) {
125
+ LOG.info("ERROR??? {}", e);
104126 }
105127 return Response.ok(app).build();
106128 }
....@@ -199,14 +221,13 @@
199221 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Application not found with ID: " + appid)
200222 .build();
201223 }
202
-
203
- if (app.getLicenseTypes() != null && !app.getLicenseTypes().isEmpty()) {
204
- return Response
205
- .status(Status.FORBIDDEN)
206
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
207
- "Application can not be deleted becasue has assigned one or more License types, ID: " + appid).build();
208
- }
209
-
224
+ /*
225
+ * if (app.getLicenseTypes() != null &&
226
+ * !app.getLicenseTypes().isEmpty()) { throw new
227
+ * SeCurisServiceException(ErrorCodes.NOT_FOUND,
228
+ * "Application can not be deleted becasue has assigned one or more License types, ID: "
229
+ * + appid); }
230
+ */
210231 em.remove(app);
211232 return Response.ok(Utils.createMap("success", true, "id", appid)).build();
212233 }
securis/src/main/java/net/curisit/securis/services/BasicServices.java
....@@ -27,6 +27,8 @@
2727 import org.apache.logging.log4j.LogManager;
2828 import org.apache.logging.log4j.Logger;
2929
30
+import com.google.inject.persist.Transactional;
31
+
3032 /**
3133 * Basic services for login and basic app wrkflow
3234 *
....@@ -98,6 +100,7 @@
98100 @Produces({
99101 MediaType.APPLICATION_JSON
100102 })
103
+ @Transactional
101104 public Response check(@HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token, @QueryParam("token") String token2) {
102105 if (token == null) {
103106 token = token2;
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -107,6 +107,7 @@
107107 LOG.info("Getting licenses list ");
108108
109109 EntityManager em = emProvider.get();
110
+ em.clear();
110111
111112 if (!bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
112113 Pack pack = em.find(Pack.class, packId);
....@@ -141,6 +142,7 @@
141142 LOG.info("Getting organization data for id: {}: ", licId);
142143
143144 EntityManager em = emProvider.get();
145
+ em.clear();
144146 License lic = getCurrentLicense(licId, bsc, em);
145147 return Response.ok(lic).build();
146148 }
....@@ -156,6 +158,7 @@
156158 @Produces({
157159 MediaType.APPLICATION_OCTET_STREAM
158160 })
161
+ @Transactional
159162 public Response download(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
160163
161164 EntityManager em = emProvider.get();
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
....@@ -32,6 +32,8 @@
3232 import net.curisit.securis.db.LicenseTypeMetadata;
3333 import net.curisit.securis.security.BasicSecurityContext;
3434 import net.curisit.securis.security.Securable;
35
+import net.curisit.securis.services.exception.SeCurisServiceException;
36
+import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes;
3537 import net.curisit.securis.utils.TokenHelper;
3638
3739 import org.apache.logging.log4j.LogManager;
....@@ -73,6 +75,7 @@
7375 LOG.info("Getting license types list ");
7476
7577 EntityManager em = emProvider.get();
78
+ em.clear();
7679 TypedQuery<LicenseType> q = em.createNamedQuery("list-license_types", LicenseType.class);
7780 List<LicenseType> list = q.getResultList();
7881
....@@ -82,6 +85,7 @@
8285 /**
8386 *
8487 * @return the server version in format majorVersion.minorVersion
88
+ * @throws SeCurisServiceException
8589 */
8690 @GET
8791 @Path("/{ltid}")
....@@ -89,7 +93,7 @@
8993 MediaType.APPLICATION_JSON
9094 })
9195 @Securable
92
- public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
96
+ public Response get(@PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) throws SeCurisServiceException {
9397 LOG.info("Getting license type data for id: {}: ", ltid);
9498 if (ltid == null || "".equals(ltid)) {
9599 LOG.error("LicenseType ID is mandatory");
....@@ -97,10 +101,11 @@
97101 }
98102
99103 EntityManager em = emProvider.get();
104
+ em.clear();
100105 LicenseType lt = em.find(LicenseType.class, Integer.parseInt(ltid));
101106 if (lt == null) {
102107 LOG.error("LicenseType with id {} not found in DB", ltid);
103
- return Response.status(Status.NOT_FOUND).build();
108
+ throw new SeCurisServiceException(ErrorCodes.NOT_FOUND, "LicenseType was not found in DB");
104109 }
105110 return Response.ok(lt).build();
106111 }
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -1,8 +1,9 @@
11 package net.curisit.securis.services;
22
3
-import java.util.ArrayList;
43 import java.util.Date;
4
+import java.util.HashSet;
55 import java.util.List;
6
+import java.util.Set;
67
78 import javax.annotation.security.RolesAllowed;
89 import javax.inject.Inject;
....@@ -35,7 +36,6 @@
3536
3637 import org.apache.logging.log4j.LogManager;
3738 import org.apache.logging.log4j.Logger;
38
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
3939
4040 import com.google.inject.persist.Transactional;
4141
....@@ -69,9 +69,8 @@
6969 public Response index(@Context BasicSecurityContext bsc) {
7070 LOG.info("Getting organizations list ");
7171
72
- BasicSecurityContext bsc2 = ResteasyProviderFactory.getContextData(BasicSecurityContext.class);
73
- LOG.debug("securityContext ROL_ADMIN?: {}", bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN));
7472 EntityManager em = emProvider.get();
73
+ em.clear();
7574 TypedQuery<Organization> q;
7675 if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
7776 LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
....@@ -103,6 +102,7 @@
103102 }
104103
105104 EntityManager em = emProvider.get();
105
+ em.clear();
106106 Organization org = em.find(Organization.class, Integer.parseInt(orgid));
107107 if (org == null) {
108108 LOG.error("Organization with id {} not found in DB", orgid);
....@@ -141,10 +141,10 @@
141141 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
142142 }
143143
144
- List<User> users = null;
145
- List<String> usersIds = org.getUsersIds();
144
+ Set<User> users = null;
145
+ Set<String> usersIds = org.getUsersIds();
146146 if (usersIds != null && !usersIds.isEmpty()) {
147
- users = new ArrayList<>();
147
+ users = new HashSet<>();
148148 for (String username : usersIds) {
149149 User user = em.find(User.class, username);
150150 if (user == null) {
....@@ -176,10 +176,10 @@
176176 org.setParentOrganization(parentOrg);
177177 }
178178
179
- private void setOrgUsers(Organization org, List<String> usersIds, EntityManager em) throws SeCurisException {
180
- List<User> users = null;
179
+ private void setOrgUsers(Organization org, Set<String> usersIds, EntityManager em) throws SeCurisException {
180
+ Set<User> users = null;
181181 if (usersIds != null && !usersIds.isEmpty()) {
182
- users = new ArrayList<>();
182
+ users = new HashSet<>();
183183 for (String username : usersIds) {
184184 User user = em.find(User.class, username);
185185 if (user == null) {
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -40,7 +40,6 @@
4040 import net.curisit.securis.services.exception.SeCurisServiceException;
4141 import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes;
4242 import net.curisit.securis.services.helpers.LicenseHelper;
43
-import net.curisit.securis.services.helpers.UserHelper;
4443 import net.curisit.securis.utils.LicUtils;
4544 import net.curisit.securis.utils.TokenHelper;
4645
....@@ -67,9 +66,6 @@
6766 Provider<EntityManager> emProvider;
6867
6968 @Inject
70
- private UserHelper userHelper;
71
-
72
- @Inject
7369 private LicenseHelper licenseHelper;
7470
7571 /**
....@@ -86,6 +82,7 @@
8682 LOG.info("Getting packs list ");
8783
8884 EntityManager em = emProvider.get();
85
+ em.clear();
8986
9087 TypedQuery<Pack> q;
9188 if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
....@@ -127,6 +124,7 @@
127124 }
128125
129126 EntityManager em = emProvider.get();
127
+ em.clear();
130128 Pack pack = em.find(Pack.class, packId);
131129 if (pack == null) {
132130 LOG.error("Pack with id {} not found in DB", packId);
securis/src/main/java/net/curisit/securis/services/UserResource.java
....@@ -76,6 +76,7 @@
7676 LOG.info("Getting users list ");
7777
7878 EntityManager em = emProvider.get();
79
+ em.clear();
7980 TypedQuery<User> q = em.createNamedQuery("list-users", User.class);
8081
8182 List<User> list = q.getResultList();
....@@ -102,6 +103,7 @@
102103 }
103104
104105 EntityManager em = emProvider.get();
106
+ em.clear();
105107 User lt = em.find(User.class, uid);
106108 if (lt == null) {
107109 LOG.error("User with id {} not found in DB", uid);
....@@ -136,7 +138,8 @@
136138 if (user.getPassword() != null && !"".equals(user.getPassword())) {
137139 user.setPassword(Utils.sha256(user.getPassword()));
138140 } else {
139
- return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User password is mandatory").build();
141
+ return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE)
142
+ .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User password is mandatory").build();
140143 }
141144 user.setModificationTimestamp(new Date());
142145 user.setLastLogin(null);
....@@ -197,7 +200,9 @@
197200 currentUser.setPassword(Utils.sha256(user.getPassword()));
198201 } else {
199202 // Password has not been modified
200
- //return Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "User password is mandatory").build();
203
+ // return
204
+ // Response.status(DefaultExceptionHandler.DEFAULT_APP_ERROR_STATUS_CODE).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
205
+ // "User password is mandatory").build();
201206 }
202207
203208 currentUser.setLastLogin(user.getLastLogin());
....@@ -238,7 +243,7 @@
238243 LOG.info("user: {}, pass: {}", username, password);
239244 LOG.info("is user in role: {} == {} ? ", "advance", request.isUserInRole("advance"));
240245 LOG.info("is user in role: {} == {} ? ", "admin", request.isUserInRole("admin"));
241
-
246
+
242247 EntityManager em = emProvider.get();
243248 User user = em.find(User.class, username);
244249 if (user == null) {
....@@ -246,7 +251,7 @@
246251 return Response.status(Status.UNAUTHORIZED).build();
247252 }
248253 String securedPassword = Utils.sha256(password);
249
-
254
+
250255 if (securedPassword == null || !securedPassword.equals(user.getPassword())) {
251256 // TODO: Code to test exception handling
252257 return Response.status(Status.UNAUTHORIZED).build();
....@@ -256,7 +261,7 @@
256261 try {
257262 em.persist(user);
258263 em.getTransaction().commit();
259
- } catch(PersistenceException ex) {
264
+ } catch (PersistenceException ex) {
260265 LOG.error("Error updating last login date for user: {}", username);
261266 LOG.error(ex);
262267 em.getTransaction().rollback();
securis/src/main/resources/META-INF/persistence.xml
....@@ -17,10 +17,9 @@
1717 <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/SeCurisDS" />
1818
1919 <property name="hibernate.cache.use_second_level_cache" value="false" />
20
- <property name="hibernate.show_sql" value="false" />
20
+ <property name="hibernate.show_sql" value="true" />
2121
22
- <!-- <property name="hibernate.format_sql" value="true"/>
23
- -->
22
+ <property name="hibernate.format_sql" value="false"/>
2423 </properties>
2524
2625 </persistence-unit>
securis/src/main/webapp/js/admin.js
....@@ -69,10 +69,7 @@
6969
7070 $scope.selectCatalog = _changeCatalog;
7171
72
- $scope.edit = function(data) {
73
- $scope.showForm = true;
74
- $scope.isNew = false;
75
- // Next line is a workaround due to some issues with values with ID == 0
72
+ $scope._loadFormu = function(elementData) {
7673 $('select').val(null);
7774 $scope.formu = {}
7875 var fields = Catalogs.getMetadata().fields;
....@@ -83,13 +80,23 @@
8380 // next lines are a workaround to avoid an issue where we try to show a form with "select" fields (if select field value doesn't change
8481 $scope.formu[field.name] = null;
8582 setTimeout(function() {
86
- $scope.formu[field.name] = data[field.name];
83
+ $scope.formu[field.name] = elementData[field.name];
8784 $scope.$apply();
8885 }, 0);
8986 } else {
90
- if (!field.listingOnly) $scope.formu[field.name] = data[field.name] || null;
87
+ if (!field.listingOnly) $scope.formu[field.name] = elementData[field.name] || null;
9188 }
9289 })
90
+ }
91
+
92
+ $scope.edit = function(data) {
93
+ $scope.showForm = true;
94
+ $scope.isNew = false;
95
+ $scope._loadFormu(data);
96
+ Catalogs.get(data[Catalogs.getPk()], function(eleData) {
97
+ $scope._loadFormu(eleData);
98
+ });
99
+ // Next line is a workaround due to some issues with values with ID == 0
93100 setTimeout(function() {
94101 $('#'+Catalogs.getFFF()).focus();
95102 }, 0);
securis/src/main/webapp/js/catalogs.js
....@@ -18,19 +18,19 @@
1818 function($rootScope, $http, $resource, $q) {
1919 var resources = {
2020 application : $resource(
21
- 'application/:appId', {
22
- appId : '@id'
21
+ 'application/:id', {
22
+ id : '@id'
2323 }),
24
- user : $resource('user/:userId', {
25
- userId : '@username'
24
+ user : $resource('user/:id', {
25
+ id : '@username'
2626 }),
2727 organization : $resource(
28
- 'organization/:orgId', {
29
- orgId : '@id'
28
+ 'organization/:id', {
29
+ id : '@id'
3030 }),
3131 licensetype : $resource(
32
- 'licensetype/:licenseTypeId', {
33
- licenseTypeId : '@id'
32
+ 'licensetype/:id', {
33
+ id : '@id'
3434 })
3535 }
3636
....@@ -68,12 +68,15 @@
6868 return resources[res];
6969 }
7070 this.getPk = function(catalogMetadata) {
71
- if (!catalogMetadata)
71
+ if (!catalogMetadata) {
7272 catalogMetadata = _current;
73
+ }
7374
74
- for (var i = 0; i < catalogMetadata.fields.length; i++)
75
- if (catalogMetadata.fields[i].pk)
75
+ for (var i = 0; i < catalogMetadata.fields.length; i++) {
76
+ if (catalogMetadata.fields[i].pk) {
7677 return catalogMetadata.fields[i].name;
78
+ }
79
+ }
7780
7881 return null;
7982 }
....@@ -167,19 +170,27 @@
167170 }
168171
169172 this.save = function(data) {
170
- if (!_current)
173
+ if (!_current) {
171174 throw new Error('There is no current catalog selected');
172
-
175
+ }
173176 var resource = this.getResource();
174177 return resource.save(data, _success, _fail);
178
+ }
179
+ this.get = function(id, _onsuccess, _onfail) {
180
+ if (!_current) {
181
+ throw new Error('There is no current catalog selected');
182
+ }
183
+ var resource = this.getResource();
184
+ return resource.get({id: id}, _onsuccess, _onfail);
175185 }
176186 this.remove = function(data) {
177187 return this.getResource().remove({}, data,
178188 _success, _fail)
179189 }
180190 this.query = function() {
181
- return this.getResource().query({},
182
- _success, _fail);
191
+ var list = this.getResource().query();
192
+ list.$promise.then(_success, _fail);
193
+ return list;
183194 }
184195 this.refreshRef = function(refs, res,
185196 preloadedData) {