Changeset 5872
- Timestamp:
- 12/01/14 16:01:52 (10 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r5802 r5872 49 49 ComponentDescription getComponentDescriptionAccessControlled(String id) throws ComponentRegistryException, UserUnauthorizedException, AuthenticationRequiredException, ItemNotFoundException; 50 50 51 ComponentDescription getComponentDescription(String id) throws ComponentRegistryException, ItemNotFoundException; 51 52 /** 52 53 * … … 74 75 ProfileDescription getProfileDescriptionAccessControlled(String id) throws ComponentRegistryException, UserUnauthorizedException, AuthenticationRequiredException, ItemNotFoundException; 75 76 77 ProfileDescription getProfileDescription(String id) throws ComponentRegistryException, ItemNotFoundException; 78 76 79 CMDComponentSpec getMDProfileAccessControled(String id) throws ComponentRegistryException, UserUnauthorizedException, AuthenticationRequiredException, ItemNotFoundException; 77 80 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r5846 r5872 227 227 } 228 228 229 private ProfileDescription getProfileDescription(String id) throws ComponentRegistryException { 230 try { 231 return ComponentUtils.toProfile(componentDao.getByCmdId(id)); 229 @Override 230 public ProfileDescription getProfileDescription(String id) throws ComponentRegistryException, ItemNotFoundException { 231 try { 232 final BaseDescription descr = componentDao.getByCmdId(id); 233 if (descr == null) { 234 throw new ItemNotFoundException("Profile not found:" + id); 235 } else { 236 return ComponentUtils.toProfile(descr); 237 } 232 238 } catch (DataAccessException ex) { 233 239 throw new ComponentRegistryException("Database access error while trying to get profile description", ex); … … 271 277 } 272 278 273 private ComponentDescription getComponentDescription(String id) throws ComponentRegistryException { 274 try { 275 return ComponentUtils.toComponent(componentDao.getByCmdId(id)); 279 @Override 280 public ComponentDescription getComponentDescription(String id) throws ComponentRegistryException, ItemNotFoundException { 281 try { 282 final BaseDescription descr = componentDao.getByCmdId(id); 283 if (descr == null) { 284 throw new ItemNotFoundException("Component not found: " + id); 285 } else { 286 return ComponentUtils.toComponent(descr); 287 } 276 288 } catch (DataAccessException ex) { 277 289 throw new ComponentRegistryException("Database access error while trying to get component description", ex); … … 934 946 if (spec != null && hasComponentId(componentId, spec.getCMDComponent())) { 935 947 LOG.debug("Component {} used in component {}", componentId, spec.getHeader().getID()); 936 result.add(getComponentDescription(id)); 948 try { 949 result.add(getComponentDescription(id)); 950 } catch (ItemNotFoundException ex) { 951 throw new ComponentRegistryException("Component not found", ex); 952 } 937 953 } 938 954 } … … 951 967 if (profile != null && hasComponentId(componentId, profile.getCMDComponent())) { 952 968 LOG.debug("Component {} used in profile {}", componentId, profile.getHeader().getID()); 953 result.add(getProfileDescription(id)); 969 try { 970 result.add(getProfileDescription(id)); 971 } catch (ItemNotFoundException ex) { 972 throw new ComponentRegistryException("Profile not found", ex); 973 } 954 974 } 955 975 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r5859 r5872 356 356 try { 357 357 final ComponentRegistry registry = this.getBaseRegistry(); 358 try {359 ComponentDescription desc = registry.getComponentDescriptionAccessControlled(componentId);360 StreamingOutput result = null;361 String fileName = desc.getName() + "." + rawType;362 if ("xml".equalsIgnoreCase(rawType)) {363 result = new StreamingOutput() {364 @Override365 public void write(OutputStream output) throws IOException,366 WebApplicationException{358 ComponentDescription desc = registry.getComponentDescription(componentId); 359 StreamingOutput result = null; 360 String fileName = desc.getName() + "." + rawType; 361 if ("xml".equalsIgnoreCase(rawType)) { 362 result = new StreamingOutput() { 363 @Override 364 public void write(OutputStream output) throws IOException, 365 WebApplicationException { 366 try { 367 367 try { 368 368 try { 369 try { 370 registry.getMDComponentAsXml(componentId, output); 371 } catch (ItemNotFoundException e1) { 372 LOG.warn("Could not retrieve component {}", 373 componentId); 374 LOG.debug("Details", e1); 375 throw new WebApplicationException(e1, Response 376 .serverError() 377 .status(Status.INTERNAL_SERVER_ERROR) 378 .build()); 379 } 380 } catch (ComponentRegistryException e) { 369 registry.getMDComponentAsXml(componentId, output); 370 } catch (ItemNotFoundException e1) { 381 371 LOG.warn("Could not retrieve component {}", 382 372 componentId); 383 LOG.debug("Details", e );384 throw new WebApplicationException(e , Response373 LOG.debug("Details", e1); 374 throw new WebApplicationException(e1, Response 385 375 .serverError() 386 376 .status(Status.INTERNAL_SERVER_ERROR) 387 377 .build()); 388 378 } 389 390 } catch (UserUnauthorizedException e2) { 391 LOG.error(e2.toString()); 379 } catch (ComponentRegistryException e) { 380 LOG.warn("Could not retrieve component {}", 381 componentId); 382 LOG.debug("Details", e); 383 throw new WebApplicationException(e, Response 384 .serverError() 385 .status(Status.INTERNAL_SERVER_ERROR) 386 .build()); 392 387 } 388 389 } catch (UserUnauthorizedException e2) { 390 LOG.error(e2.toString()); 393 391 } 394 }; 395 return createDownloadResponse(result, fileName); 396 } else if ("xsd".equalsIgnoreCase(rawType)) { 397 result = new StreamingOutput() { 398 @Override 399 public void write(OutputStream output) throws IOException, 400 WebApplicationException { 392 } 393 }; 394 return createDownloadResponse(result, fileName); 395 } else if ("xsd".equalsIgnoreCase(rawType)) { 396 result = new StreamingOutput() { 397 @Override 398 public void write(OutputStream output) throws IOException, 399 WebApplicationException { 400 try { 401 401 try { 402 402 try { 403 try { 404 registry.getMDComponentAsXsd(componentId, output); 405 } catch (ItemNotFoundException e1) { 406 LOG.warn("Could not retrieve component {}", 407 componentId); 408 LOG.debug("Details", e1); 409 throw new WebApplicationException(e1, Response 410 .serverError() 411 .status(Status.INTERNAL_SERVER_ERROR) 412 .build()); 413 } 414 } catch (ComponentRegistryException e) { 403 registry.getMDComponentAsXsd(componentId, output); 404 } catch (ItemNotFoundException e1) { 415 405 LOG.warn("Could not retrieve component {}", 416 406 componentId); 417 LOG.debug("Details", e );418 throw new WebApplicationException(e , Response407 LOG.debug("Details", e1); 408 throw new WebApplicationException(e1, Response 419 409 .serverError() 420 410 .status(Status.INTERNAL_SERVER_ERROR) 421 411 .build()); 422 412 } 423 } catch (UserUnauthorizedException e2) { 424 LOG.error(e2.toString()); 413 } catch (ComponentRegistryException e) { 414 LOG.warn("Could not retrieve component {}", 415 componentId); 416 LOG.debug("Details", e); 417 throw new WebApplicationException(e, Response 418 .serverError() 419 .status(Status.INTERNAL_SERVER_ERROR) 420 .build()); 425 421 } 426 422 } catch (UserUnauthorizedException e2) { 423 LOG.error(e2.toString()); 427 424 } 428 }; 429 return createDownloadResponse(result, fileName); 430 } else { 431 return Response.status(Status.NOT_FOUND).entity("Usupported raw type " + rawType).build(); 432 } 433 434 } catch (UserUnauthorizedException e2) { 435 return Response.status(Status.FORBIDDEN).build(); 425 426 } 427 }; 428 return createDownloadResponse(result, fileName); 429 } else { 430 return Response.status(Status.NOT_FOUND).entity("Usupported raw type " + rawType).build(); 436 431 } 437 432 } catch (ItemNotFoundException e3) { … … 1186 1181 final ComponentRegistry registry = this.getBaseRegistry(); 1187 1182 1188 ProfileDescription desc = registry.getProfileDescriptionAccessControlled(profileId);1183 final ProfileDescription desc = registry.getProfileDescription(profileId); 1189 1184 if (desc == null) { 1190 1185 return Response.status(Status.NOT_FOUND).build(); … … 1233 1228 } 1234 1229 return createDownloadResponse(result, fileName); 1235 } catch (UserUnauthorizedException ex) {1236 return Response.status(Status.FORBIDDEN).build();1237 1230 } catch (ItemNotFoundException e) { 1238 1231 return Response.serverError().status(Status.NOT_FOUND) -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RestGroupServiceTest.java
r5832 r5872 44 44 * 45 45 * Test groups: 46 * 46 * 47 47 * A 48 * Owner: Dummy 49 * Members: - 50 * Items: profile-1, component-1, component-2 51 * 48 * Owner: Dummy Members: - Items: profile-1, component-1, component-2 49 * 52 50 * B 53 * Owner: anotherPrincipal 54 * Members: Dummy 55 * Items: Bprofile-1, Bcomponent-1, Bcomponent-2 56 * 51 * Owner: anotherPrincipal Members: Dummy Items: Bprofile-1, Bcomponent-1, 52 * Bcomponent-2 53 * 57 54 * C 58 * Owner: anotherPrincipal 59 * Members: - 60 * Items: Cprofile-1, Ccomponent-1, Ccomponent-2 61 * 55 * Owner: anotherPrincipal Members: - Items: Cprofile-1, Ccomponent-1, 56 * Ccomponent-2 57 * 62 58 * D 63 * Owner: anotherPrincipal 64 * Members: Dummy, anotherPrincipal 65 * Items: Dprofile-1, Dcomponent-1, Dcomponent-2 66 * 59 * Owner: anotherPrincipal Members: Dummy, anotherPrincipal Items: Dprofile-1, 60 * Dcomponent-1, Dcomponent-2 61 * 67 62 * @author olhsha 68 63 * @author twagoo … … 160 155 } 161 156 162 private void MakeGroupC() throws ItemNotFoundException{157 private void MakeGroupC() throws ItemNotFoundException { 163 158 groupService.createNewGroup("group C", "anotherPrincipal"); 164 159 } … … 189 184 } 190 185 191 private void MakeGroupD() throws ItemNotFoundException{186 private void MakeGroupD() throws ItemNotFoundException { 192 187 groupService.createNewGroup("group D", "anotherPrincipal"); 193 188 groupService.makeMember("anotherPrincipal", "group D"); … … 220 215 } 221 216 222 223 217 // List<Group> getGroupsTheCurrentUserIsAMemberOf(); 224 218 @Test … … 239 233 // Response transferItemOwnershipToGroup(String itemId, long groupId) throws IOException; 240 234 // 235 241 236 @Test 242 237 public void testTransferOwnership() throws Exception { … … 278 273 } 279 274 280 281 275 @Test 282 276 public void testTransferOwnershipBetweenGroups() throws Exception { … … 288 282 fillUpGroupD(); 289 283 // test itself 290 284 291 285 // this profile was created and moved into group D by someone else 292 286 String test_profile_id = ProfileDescription.PROFILE_PREFIX + "Dprofile-1"; … … 296 290 // I am member of both groups, so should be allowed 297 291 assertEquals("Moving between groups should be allowed as long as user is member", 200, cr.getStatus()); 298 292 299 293 // this component was created and moved into group D by someone else 300 294 String test_component_id = ComponentDescription.COMPONENT_PREFIX + "Dcomponent-1"; … … 304 298 // I am not a member of groups C, so should not be allowed 305 299 assertEquals("Moving between groups should not be allowed if user is not member", 403, cr.getStatus()); 306 307 308 // component in group C 300 301 // component in group C 309 302 test_component_id = ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1"; 310 303 // try to move to group B (which I am a member of) … … 313 306 // I am not a member of group C, so should not be allowed 314 307 assertEquals("Moving between groups should not be allowed if user is not member", 403, cr.getStatus()); 315 316 } 317 308 309 } 310 318 311 @Test 319 312 public void testGetGroupProfilesAndComponents() throws Exception { … … 410 403 (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1", ProfileDescription.PROFILE_PREFIX + "Cprofile-1", "anotherPrincipal"); 411 404 412 405 // lists 413 406 List<Comment> response = this.getAuthenticatedResource(getResource() 414 407 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/")) … … 497 490 fillUpGroupC(); 498 491 499 492 // lists of profiles and components 500 493 Rss response = this.getAuthenticatedResource(getResource() 501 494 .path("/registry/profiles/rss").queryParam("registrySpace", REGISTRY_SPACE_GROUP).queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML) … … 536 529 (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1", ProfileDescription.PROFILE_PREFIX + "Cprofile-1", "anotherPrincipal"); 537 530 538 531 // lists 539 532 response = this.getAuthenticatedResource(getResource() 540 533 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/rss")) … … 1099 1092 .path("/registry/components/" + id + "/xsd")) 1100 1093 .accept(MediaType.TEXT_XML).get(ClientResponse.class); 1101 assertEquals( 403, resp.getStatus());1094 assertEquals("XSD should always be available", 200, resp.getStatus()); 1102 1095 1103 1096 id = ProfileDescription.PROFILE_PREFIX + "Cprofile-1"; … … 1105 1098 .path("/registry/profiles/" + id + "/xsd")) 1106 1099 .accept(MediaType.TEXT_XML).get(ClientResponse.class); 1107 assertEquals( 403, resp.getStatus());1100 assertEquals("XSD should always be available", 200, resp.getStatus()); 1108 1101 1109 1102 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java
r5568 r5872 276 276 .path("/registry/components/" + id + "/xsd")) 277 277 .accept(MediaType.TEXT_XML).get( ClientResponse.class); 278 assertEquals( 403, resp.getStatus());278 assertEquals("XSD should always be available", 200, resp.getStatus()); 279 279 280 280 id = ProfileDescription.PROFILE_PREFIX + "Cprofile-1"; … … 282 282 .path("/registry/profiles/" + id + "/xsd")) 283 283 .accept(MediaType.TEXT_XML).get( ClientResponse.class); 284 assertEquals( 403, resp.getStatus());284 assertEquals("XSD should always be available", 200, resp.getStatus()); 285 285 286 286
Note: See TracChangeset
for help on using the changeset viewer.