Changeset 5030
- Timestamp:
- 04/23/14 15:20:54 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/Helpers.java
r4997 r5030 45 45 String result = (new StringBuilder(text)).toString(); 46 46 for (String tempTarget : pairs.keySet()) { 47 result = result.replaceAll(tempTarget, pairs.get(tempTarget)); 47 if (tempTarget != null) { 48 if (!tempTarget.trim().equals("")) { 49 result = result.replaceAll(tempTarget, pairs.get(tempTarget)); 50 } 51 } 48 52 } 49 53 return result; … … 65 69 return result; 66 70 } 67 71 68 72 public static String welcomeString(String baseUri) { 69 73 String welcome = "<!DOCTYPE html><body>" … … 74 78 return welcome; 75 79 } 76 80 77 81 public static Principal createPrincipalElement(String name, String e_mail) { 78 82 Principal result = new Principal(); … … 81 85 return result; 82 86 } 83 87 84 88 public static String hashPswd(String pswd, int strength, String salt) { 85 ShaPasswordEncoder encoder = new ShaPasswordEncoder(strength);86 return encoder.encodePassword(pswd, salt);89 ShaPasswordEncoder encoder = new ShaPasswordEncoder(strength); 90 return encoder.encodePassword(pswd, salt); 87 91 } 88 92 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/PrincipalResource.java
r5022 r5030 74 74 Map params = new HashMap<String, String>(); 75 75 params.put("externalId", externalIdentifier); 76 Principal principal = (Principal) this.wrapGetResource(params, new GetPrincipal()); 77 if (principal != null) { 78 return new ObjectFactory().createPrincipal(principal); 79 } else { 80 return new ObjectFactory().createPrincipal(new Principal()); 81 } 76 return this.wrapPrincipalRequest(params, new GetPrincipal()); 82 77 } 83 78 … … 101 96 Map params = new HashMap<String, String>(); 102 97 params.put("email", email); 103 Principal principal = (Principal) this.wrapGetResource(params, new GetPrincipalByInfo()); 104 if (principal != null) { 105 return new ObjectFactory().createPrincipal(principal); 106 } else { 107 return new ObjectFactory().createPrincipal(new Principal()); 108 } 109 98 return this.wrapPrincipalRequest(params, new GetPrincipalByInfo()); 110 99 } 111 100 … … 118 107 params.put("externalId", externalIdentifier); 119 108 params.put("resource", this); 120 CurrentPrincipalInfo result = (CurrentPrincipalInfo) this.wrapGetResource(params, new GetCurrentPrincipalInfo()); 121 if (result != null) { 122 return new ObjectFactory().createCurrentPrincipalInfo(result); 123 } else { 124 return new ObjectFactory().createCurrentPrincipalInfo(new CurrentPrincipalInfo()); 125 } 109 return this.wrapCurrentPrincipalInfoRequest(params, new GetCurrentPrincipalInfo()); 110 126 111 } 127 112 … … 162 147 163 148 if (dbIntegrityService.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 164 return this.wrap AddOrUpdatePrincipal(params, new AddPrincipal());149 return this.wrapPrincipalRequest(params, new AddPrincipal()); 165 150 } else { 166 151 verboseOutput.ADMIN_RIGHTS_EXPECTED(); … … 190 175 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 191 176 192 return this.wrap AddOrUpdatePrincipal(params, new RegisterNonShibbolizedPrincipal());177 return this.wrapPrincipalRequest(params, new RegisterNonShibbolizedPrincipal()); 193 178 194 179 } … … 209 194 params.put("newPrincipal", newPrincipal); 210 195 211 return this.wrap AddOrUpdatePrincipal(params, new AddPrincipal());196 return this.wrapPrincipalRequest(params, new AddPrincipal()); 212 197 } 213 198 … … 236 221 237 222 if (dbIntegrityService.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) { 238 return this.wrap AddOrUpdatePrincipal(params, new UpdatePrincipal());223 return this.wrapPrincipalRequest(params, new UpdatePrincipal()); 239 224 } else { 240 225 verboseOutput.ADMIN_RIGHTS_EXPECTED(); … … 264 249 params.put("newPrincipal", newPrincipal); 265 250 266 return this.wrap AddOrUpdatePrincipal(params, new UpdatePrincipal());251 return this.wrapPrincipalRequest(params, new UpdatePrincipal()); 267 252 } 268 253 … … 366 351 367 352 368 private class GetPrincipal implements ILambda<Map <String, String>, Principal> {369 370 @Override 371 public Principal apply(Map <String, String>params) throws NotInDataBaseException, PrincipalExists {372 final Number principalID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString( params.get("externalId")), Resource.PRINCIPAL);353 private class GetPrincipal implements ILambda<Map, Principal> { 354 355 @Override 356 public Principal apply(Map params) throws NotInDataBaseException, PrincipalExists { 357 final Number principalID = dbIntegrityService.getResourceInternalIdentifier(UUID.fromString((String) params.get("externalId")), Resource.PRINCIPAL); 373 358 return dbIntegrityService.getPrincipal(principalID); 374 359 } 375 360 } 376 361 377 private class GetPrincipalByInfo implements ILambda<Map <String, String>, Principal> {378 379 @Override 380 public Principal apply(Map <String, String>params) throws NotInDataBaseException, PrincipalExists {381 return dbIntegrityService.getPrincipalByInfo( params.get("email"));362 private class GetPrincipalByInfo implements ILambda<Map, Principal> { 363 364 @Override 365 public Principal apply(Map params) throws NotInDataBaseException, PrincipalExists { 366 return dbIntegrityService.getPrincipalByInfo((String) params.get("email")); 382 367 } 383 368 } … … 396 381 397 382 //// wrappers that map main working methods into exception handling //// 398 private JAXBElement<Principal> wrapAddOrUpdatePrincipal(Map params, ILambda<Map, Principal> changer) throws IOException { 383 384 385 386 387 private JAXBElement<Principal> wrapPrincipalRequest(Map params, ILambda<Map, Principal> dbRequestor) throws IOException { 399 388 Number remotePrincipalID = this.getPrincipalID(); 400 389 if (remotePrincipalID == null) { … … 403 392 try { 404 393 try { 405 return new ObjectFactory().createPrincipal( changer.apply(params));394 return new ObjectFactory().createPrincipal(dbRequestor.apply(params)); 406 395 } catch (NotInDataBaseException e1) { 407 396 loggerServer.debug(e1.toString()); … … 416 405 417 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 } 418 428 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/ResourceResource.java
r5022 r5030 101 101 } 102 102 103 protected T wrapGetResource(Map params, ILambda<Map, T> getter) throws IOException { 104 Number remotePrincipalID = this.getPrincipalID(); 105 if (remotePrincipalID == null) { 106 return null; 107 } 108 try { 109 try { 110 return getter.apply(params); 111 } catch (NotInDataBaseException e1) { 112 loggerServer.debug(e1.toString()); 113 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString()); 114 return null; 115 } 116 } catch (PrincipalExists e) { 117 loggerServer.debug(e.toString()); 118 httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); 119 return null; 120 } 121 122 } 103 123 104 }
Note: See TracChangeset
for help on using the changeset viewer.