#394 feature - Several fixes related with form management
| .. | .. |
|---|
| 136 | 136 | // information about the referenced entities. |
|---|
| 137 | 137 | @JsonProperty("org_parent_id") |
|---|
| 138 | 138 | public void setParentOrgId(Integer orgId) { |
|---|
| 139 | | - parentOrganization = new Organization(); |
|---|
| 140 | | - parentOrganization.setId(orgId); |
|---|
| 139 | + if (orgId != null) { |
|---|
| 140 | + parentOrganization = new Organization(); |
|---|
| 141 | + parentOrganization.setId(orgId); |
|---|
| 142 | + } else { |
|---|
| 143 | + parentOrganization = null; |
|---|
| 144 | + } |
|---|
| 141 | 145 | } |
|---|
| 142 | 146 | |
|---|
| 143 | 147 | @JsonProperty("org_parent_id") |
|---|
| .. | .. |
|---|
| 111 | 111 | log.error("LicenseType application with id {} not found in DB", lt.getApplicationId()); |
|---|
| 112 | 112 | return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "License type's app not found with ID: " + lt.getApplicationId()).build(); |
|---|
| 113 | 113 | } |
|---|
| 114 | + } else { |
|---|
| 115 | + log.error("Application is missing for current license type data"); |
|---|
| 116 | + return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Application is missing for current license type data").build(); |
|---|
| 114 | 117 | } |
|---|
| 115 | 118 | |
|---|
| 116 | 119 | lt.setApplication(app); |
|---|
| .. | .. |
|---|
| 96 | 96 | return Response.ok(lt).build(); |
|---|
| 97 | 97 | } |
|---|
| 98 | 98 | |
|---|
| 99 | + private boolean isCyclicalRelationship(int currentId, Organization parent) { |
|---|
| 100 | + while (parent != null) { |
|---|
| 101 | + if (parent.getId() == currentId) |
|---|
| 102 | + return true; |
|---|
| 103 | + parent = parent.getParentOrganization(); |
|---|
| 104 | + } |
|---|
| 105 | + return false; |
|---|
| 106 | + } |
|---|
| 107 | + |
|---|
| 99 | 108 | @POST |
|---|
| 100 | 109 | @Path("/") |
|---|
| 101 | 110 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| .. | .. |
|---|
| 157 | 166 | log.error("Organization parent with id {} not found in DB", org.getParentOrgId()); |
|---|
| 158 | 167 | return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's parent not found with ID: " + org.getParentOrgId()).build(); |
|---|
| 159 | 168 | } |
|---|
| 169 | + if (isCyclicalRelationship(currentOrg.getId(), parentOrg)) { |
|---|
| 170 | + log.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId()); |
|---|
| 171 | + return Response.status(Status.FORBIDDEN).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Cyclical relationships are not allowed, please change the parent organization, current Parent: " + parentOrg.getName()).build(); |
|---|
| 172 | + } |
|---|
| 160 | 173 | } |
|---|
| 161 | 174 | |
|---|
| 162 | 175 | List<User> users = null; |
|---|
| .. | .. |
|---|
| 165 | 178 | users = new ArrayList<>(); |
|---|
| 166 | 179 | for (String username : usersIds) { |
|---|
| 167 | 180 | User user = em.find(User.class, username); |
|---|
| 168 | | - if (parentOrg == null) { |
|---|
| 169 | | - log.error("Organization user with id {} not found in DB", username); |
|---|
| 181 | + if (user == null) { |
|---|
| 182 | + log.error("Organization user with id '{}' not found in DB", username); |
|---|
| 170 | 183 | return Response.status(Status.NOT_FOUND).header(SecurisErrorHandler.HEADER_ERROR_MESSAGE, "Organization's user not found with ID: " + username).build(); |
|---|
| 171 | 184 | } |
|---|
| 172 | 185 | users.add(user); |
|---|
| .. | .. |
|---|
| 89 | 89 | } |
|---|
| 90 | 90 | |
|---|
| 91 | 91 | EntityManager em = emProvider.get(); |
|---|
| 92 | | - User lt = em.find(User.class, Integer.parseInt(uid)); |
|---|
| 92 | + User lt = em.find(User.class, uid); |
|---|
| 93 | 93 | if (lt == null) { |
|---|
| 94 | 94 | log.error("User with id {} not found in DB", uid); |
|---|
| 95 | 95 | return Response.status(Status.NOT_FOUND).build(); |
|---|
| .. | .. |
|---|
| 187 | 187 | public Response delete(@PathParam("uid") String uid, @Context HttpServletRequest request) { |
|---|
| 188 | 188 | log.info("Deleting app with id: {}", uid); |
|---|
| 189 | 189 | EntityManager em = emProvider.get(); |
|---|
| 190 | | - User app = em.find(User.class, Integer.parseInt(uid)); |
|---|
| 190 | + User app = em.find(User.class, uid); |
|---|
| 191 | 191 | if (app == null) { |
|---|
| 192 | 192 | log.error("User with id {} can not be deleted, It was not found in DB", uid); |
|---|
| 193 | 193 | return Response.status(Status.NOT_FOUND).build(); |
|---|
| .. | .. |
|---|
| 154 | 154 | <p ng-switch-when="readonly" class="form-control-static">{{formu[field.name]}}</p> |
|---|
| 155 | 155 | <p ng-switch-when="readonly_date" class="form-control-static">{{formu[field.name] | date:'medium'}}</p> |
|---|
| 156 | 156 | <select ng-switch-when="select" class="form-control" ng-required="field.mandatory" ng-model="formu[field.name]" |
|---|
| 157 | | - ng-options="o.id as o.label for o in refs[field.name]"> |
|---|
| 157 | + ng-options="o.id as o.label for o in refs[field.name]" > |
|---|
| 158 | + <option selected="true" ng-if="!field.mandatory" value=""></option> |
|---|
| 158 | 159 | </select> |
|---|
| 159 | 160 | <select chosen multiple ng-switch-when="multiselect" class="form-control" ng-required="field.mandatory" ng-model="formu[field.name]" |
|---|
| 160 | 161 | ng-options="o.id as o.label for o in refs[field.name]" data-placeholder="..."> |
|---|
| .. | .. |
|---|
| 62 | 62 | $scope.edit = function(data) { |
|---|
| 63 | 63 | $scope.showForm = true; |
|---|
| 64 | 64 | $scope.isNew = false; |
|---|
| 65 | + // Next line is a wirkaround due to some issues with values with ID == 0 |
|---|
| 66 | + $('select').val(null); |
|---|
| 65 | 67 | $scope.formu = {} |
|---|
| 66 | | - for (var k in data) { |
|---|
| 67 | | - if (k.indexOf('$') !== 0 && k.indexOf('_') !== 0 && !Catalogs.getField(k).listingOnly) $scope.formu[k] = data[k] |
|---|
| 68 | | - } |
|---|
| 68 | + var fields = Catalogs.getMetadata().fields; |
|---|
| 69 | + console.log($scope); |
|---|
| 70 | + |
|---|
| 71 | + fields.forEach(function(field) { |
|---|
| 72 | + if (!field.listingOnly) $scope.formu[field.name] = data[field.name] || null; |
|---|
| 73 | + }) |
|---|
| 69 | 74 | |
|---|
| 70 | 75 | setTimeout(function() { |
|---|
| 71 | 76 | $('#'+Catalogs.getFFF()).focus(); |
|---|
| .. | .. |
|---|
| 117 | 122 | $scope.editNew = function() { |
|---|
| 118 | 123 | $scope.$parent.isNew = true; |
|---|
| 119 | 124 | $scope.$parent.showForm = true; |
|---|
| 125 | + $('select').val(null); |
|---|
| 120 | 126 | $scope.$parent.formu = {}; |
|---|
| 121 | 127 | setTimeout(function() { |
|---|
| 122 | 128 | $('#'+Catalogs.getFFF()).focus(); |
|---|
| .. | .. |
|---|
| 125 | 131 | } |
|---|
| 126 | 132 | $scope.cancel = function() { |
|---|
| 127 | 133 | $scope.$parent.showForm = false; |
|---|
| 134 | + $scope.catalogForm.$setPristine(); |
|---|
| 128 | 135 | } |
|---|
| 129 | 136 | |
|---|
| 130 | 137 | $scope.saveCatalog = function() { |
|---|
| .. | .. |
|---|
| 134 | 141 | var promise = Catalogs.save($scope.formu).$promise; |
|---|
| 135 | 142 | promise.then(function(data, otro) { |
|---|
| 136 | 143 | if ($scope.isNew) { |
|---|
| 144 | + $scope.catalogForm.$setPristine(); |
|---|
| 137 | 145 | $scope.$parent.formu = {} |
|---|
| 138 | 146 | $('#'+ Catalogs.getFFF()).focus(); |
|---|
| 139 | 147 | } else { |
|---|
| .. | .. |
|---|
| 183 | 183 | $q.all(promises).then(function() { |
|---|
| 184 | 184 | |
|---|
| 185 | 185 | for (var k in refs) { |
|---|
| 186 | | - var pk = that.getPk(that.getMetadata(that.getField(k).resource)) |
|---|
| 186 | + var field = that.getField(k); |
|---|
| 187 | + var pk = that.getPk(that.getMetadata(field.resource)) |
|---|
| 187 | 188 | console.log('PK field for ' + k + ' is ' + pk) |
|---|
| 188 | 189 | var comboData = [] |
|---|
| 189 | 190 | refs[k].forEach(function(row) { |
|---|
| 191 | + console.log('field.resource !== _current.resource: ' + field.resource +' '+ _current.resource) |
|---|
| 190 | 192 | comboData.push({ |
|---|
| 191 | 193 | id: row[pk], |
|---|
| 192 | | - label: row.label || row.name || row.code || row.first_name + ' ' + row.last_name |
|---|
| 194 | + label: row.label || row.name || row.code || row.first_name + ' ' + (row.last_name || '') |
|---|
| 193 | 195 | }); |
|---|
| 194 | 196 | }) |
|---|
| 195 | 197 | refs[k] = comboData; |
|---|
| .. | .. |
|---|
| 61 | 61 | "name" : "application_id", |
|---|
| 62 | 62 | "display" : "Application", |
|---|
| 63 | 63 | "resource" : "application", |
|---|
| 64 | + "mandatory" : true, |
|---|
| 64 | 65 | "type" : "select" |
|---|
| 65 | 66 | }, { |
|---|
| 66 | 67 | "name" : "creationTimestamp", |
|---|