Changeset 5053
- Timestamp:
- 04/24/14 16:34:51 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/ILambda.java
r5022 r5053 19 19 20 20 import eu.dasish.annotation.backend.NotInDataBaseException; 21 import eu.dasish.annotation.backend.PrincipalExists;22 21 23 22 /** … … 27 26 public interface ILambda<Map, R> { 28 27 29 public R apply(Map params) throws NotInDataBaseException , PrincipalExists;28 public R apply(Map params) throws NotInDataBaseException; 30 29 31 30 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r4969 r5053 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 21 import eu.dasish.annotation.backend.NotInDataBaseException; 22 import eu.dasish.annotation.backend.PrincipalExists; 22 23 import eu.dasish.annotation.backend.Resource; 24 import eu.dasish.annotation.backend.dao.ILambda; 23 25 import eu.dasish.annotation.schema.Annotation; 24 26 import eu.dasish.annotation.schema.AnnotationBody; … … 31 33 import java.io.IOException; 32 34 import java.util.Arrays; 35 import java.util.Map; 33 36 import java.util.UUID; 34 37 import javax.servlet.http.HttpServletRequest; … … 414 417 } 415 418 } 419 420 //////////////////////////////////////////////// 421 422 423 416 424 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/PrincipalResource.java
r5030 r5053 23 23 import eu.dasish.annotation.backend.Resource; 24 24 import eu.dasish.annotation.backend.dao.ILambda; 25 import eu.dasish.annotation.backend.dao.ILambdaPrincipal; 25 26 import eu.dasish.annotation.schema.CurrentPrincipalInfo; 26 27 import eu.dasish.annotation.schema.ObjectFactory; … … 74 75 Map params = new HashMap<String, String>(); 75 76 params.put("externalId", externalIdentifier); 76 return this.wrapPrincipalRequest(params, new GetPrincipal()); 77 Principal result = (Principal) (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapRequestResource(params, new GetPrincipal()); 78 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 77 79 } 78 80 … … 96 98 Map params = new HashMap<String, String>(); 97 99 params.put("email", email); 98 return this.wrapPrincipalRequest(params, new GetPrincipalByInfo()); 100 Principal result = (Principal) (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapRequestResource(params, new GetPrincipalByInfo()); 101 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 99 102 } 100 103 … … 107 110 params.put("externalId", externalIdentifier); 108 111 params.put("resource", this); 109 return this.wrapCurrentPrincipalInfoRequest(params, new GetCurrentPrincipalInfo());110 112 CurrentPrincipalInfo result = (CurrentPrincipalInfo) (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapRequestResource(params, new GetCurrentPrincipalInfo()); 113 return (result != null) ? (new ObjectFactory().createCurrentPrincipalInfo(result)) : (new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo())); 111 114 } 112 115 … … 147 150 148 151 if (dbIntegrityService.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 149 return this.wrapPrincipalRequest(params, new AddPrincipal());152 return (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapAddPrincipalRequest(params, new AddPrincipal()); 150 153 } else { 151 154 verboseOutput.ADMIN_RIGHTS_EXPECTED(); … … 174 177 175 178 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 176 177 return this.wrapPrincipalRequest(params, new RegisterNonShibbolizedPrincipal()); 178 179 return (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapAddPrincipalRequest(params, new RegisterNonShibbolizedPrincipal()); 179 180 } 180 181 … … 194 195 params.put("newPrincipal", newPrincipal); 195 196 196 return this.wrapPrincipalRequest(params, new AddPrincipal()); 197 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 198 return (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapAddPrincipalRequest(params, new AddPrincipal()); 197 199 } 198 200 … … 221 223 222 224 if (dbIntegrityService.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 223 return this.wrapPrincipalRequest(params, new UpdatePrincipal()); 225 Principal result = (Principal) (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapRequestResource(params, new UpdatePrincipal()); 226 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 227 224 228 } else { 225 229 verboseOutput.ADMIN_RIGHTS_EXPECTED(); … … 248 252 Map params = new HashMap<String, Object>(); 249 253 params.put("newPrincipal", newPrincipal); 250 251 return this.wrapPrincipalRequest(params, new UpdatePrincipal());254 Principal result = (Principal) (new RequestWrappers(loggerServer, httpServletResponse, this, dbIntegrityService)).wrapRequestResource(params, new UpdatePrincipal()); 255 return (result != null) ? (new ObjectFactory().createPrincipal(result)) : (new ObjectFactory().createPrincipal(new Principal())); 252 256 } 253 257 … … 319 323 } 320 324 321 /////////////// main working methods that call db-services /////322 private class RegisterNonShibbolizedPrincipal implements ILambda <Map, Principal> {325 /////////////// main working methods that call db-services and sent as aparameters to correponding wrappers///// 326 private class RegisterNonShibbolizedPrincipal implements ILambdaPrincipal<Map, Principal> { 323 327 324 328 @Override … … 330 334 } 331 335 332 private class AddPrincipal implements ILambda <Map, Principal> {336 private class AddPrincipal implements ILambdaPrincipal<Map, Principal> { 333 337 334 338 @Override … … 342 346 343 347 @Override 344 public Principal apply(Map params) throws NotInDataBaseException , PrincipalExists{348 public Principal apply(Map params) throws NotInDataBaseException { 345 349 Principal principal = (Principal) params.get("newPrincipal"); 346 350 Number principalID = dbIntegrityService.getResourceInternalIdentifierFromURI(principal.getURI(), Resource.PRINCIPAL); … … 350 354 } 351 355 352 353 356 private class GetPrincipal implements ILambda<Map, Principal> { 354 357 355 358 @Override 356 public Principal apply(Map params) throws NotInDataBaseException , PrincipalExists{359 public Principal apply(Map params) throws NotInDataBaseException { 357 360 final Number principalID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString((String) params.get("externalId")), Resource.PRINCIPAL); 358 361 return dbIntegrityService.getPrincipal(principalID); … … 363 366 364 367 @Override 365 public Principal apply(Map params) throws NotInDataBaseException , PrincipalExists{368 public Principal apply(Map params) throws NotInDataBaseException { 366 369 return dbIntegrityService.getPrincipalByInfo((String) params.get("email")); 367 370 } … … 371 374 372 375 @Override 373 public CurrentPrincipalInfo apply(Map params) throws NotInDataBaseException , PrincipalExists{376 public CurrentPrincipalInfo apply(Map params) throws NotInDataBaseException { 374 377 final Number principalID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString((String) params.get("externalId")), Resource.PRINCIPAL); 375 378 final CurrentPrincipalInfo principalInfo = new CurrentPrincipalInfo(); … … 379 382 } 380 383 } 381 382 //// wrappers that map main working methods into exception handling ////383 384 385 386 387 private JAXBElement<Principal> wrapPrincipalRequest(Map params, ILambda<Map, Principal> dbRequestor) throws IOException {388 Number remotePrincipalID = this.getPrincipalID();389 if (remotePrincipalID == null) {390 return new ObjectFactory().createPrincipal(new Principal());391 }392 try {393 try {394 return new ObjectFactory().createPrincipal(dbRequestor.apply(params));395 } catch (NotInDataBaseException e1) {396 loggerServer.debug(e1.toString());397 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());398 return new ObjectFactory().createPrincipal(new Principal());399 }400 } catch (PrincipalExists e) {401 loggerServer.debug(e.toString());402 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());403 return new ObjectFactory().createPrincipal(new Principal());404 }405 406 }407 408 private JAXBElement<CurrentPrincipalInfo> wrapCurrentPrincipalInfoRequest(Map params, ILambda<Map, CurrentPrincipalInfo> dbRequestor) throws IOException {409 Number remotePrincipalID = this.getPrincipalID();410 if (remotePrincipalID == null) {411 return new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo());412 }413 try {414 try {415 return new ObjectFactory().createCurrentPrincipalInfo(dbRequestor.apply(params));416 } catch (NotInDataBaseException e1) {417 loggerServer.debug(e1.toString());418 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());419 return new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo());420 }421 } catch (PrincipalExists e) {422 loggerServer.debug(e.toString());423 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());424 return new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo());425 }426 427 }428 384 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/VerboseOutput.java
r4969 r5053 35 35 36 36 37 p rivateString _FORBIDDEN_RESOURCE_ACTION(String identifier, String resource, String action, String ownerName, String ownerEMail) {37 public String _FORBIDDEN_RESOURCE_ACTION(String identifier, String resource, String action, String ownerName, String ownerEMail) { 38 38 return " The logged-in principal cannot " + action + " the " + resource + " with the identifier " + identifier + ". Contact the resource's owner " + ownerName + " via the e-mail " + ownerEMail; 39 39 }
Note: See TracChangeset
for help on using the changeset viewer.