Changeset 1862
- Timestamp:
- 04/05/12 14:52:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r1860 r1862 52 52 @Path("/registry") 53 53 public class ComponentRegistryRestService { 54 54 55 55 @Context 56 56 private UriInfo uriInfo; … … 69 69 @Inject(value = "componentRegistryFactory") 70 70 private ComponentRegistryFactory componentRegistryFactory; 71 71 72 72 private ComponentRegistry getRegistry(boolean userspace) { 73 73 Principal userPrincipal = security.getUserPrincipal(); … … 75 75 return getRegistry(userspace, userCredentials); 76 76 } 77 77 78 78 private ComponentRegistry getRegistry(boolean userspace, UserCredentials userCredentials) { 79 79 return componentRegistryFactory.getComponentRegistry(userspace, userCredentials); … … 92 92 return principal; 93 93 } 94 94 95 95 private UserCredentials getUserCredentials(Principal userPrincipal) { 96 96 UserCredentials userCredentials = null; … … 100 100 return userCredentials; 101 101 } 102 102 103 103 @GET 104 104 @Path("/components") … … 111 111 return components; 112 112 } 113 113 114 114 @GET 115 115 @Path("/profiles") … … 118 118 @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException { 119 119 long start = System.currentTimeMillis(); 120 120 121 121 List<ProfileDescription> profiles; 122 122 if (metadataEditor) { … … 125 125 profiles = getRegistry(userspace).getProfileDescriptions(); 126 126 } 127 127 128 128 LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start) 129 129 + " millisecs)"); 130 130 return profiles; 131 131 } 132 132 133 133 @GET 134 134 @Path("/components/{componentId}") … … 139 139 return getRegistry(userspace).getMDComponent(componentId); 140 140 } 141 141 142 142 @GET 143 143 @Path("/components/{componentId}/{rawType}") … … 156 156 if ("xml".equalsIgnoreCase(rawType)) { 157 157 result = new StreamingOutput() { 158 158 159 159 @Override 160 160 public void write(OutputStream output) throws IOException, WebApplicationException { … … 169 169 } else if ("xsd".equalsIgnoreCase(rawType)) { 170 170 result = new StreamingOutput() { 171 171 172 172 @Override 173 173 public void write(OutputStream output) throws IOException, WebApplicationException { … … 178 178 throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build()); 179 179 } 180 180 181 181 } 182 182 }; … … 191 191 } 192 192 } 193 193 194 194 public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) throws ComponentRegistryException { 195 195 AbstractDescription desc = null; … … 208 208 return result; 209 209 } 210 210 211 211 @GET 212 212 @Path("/profiles/{profileId}") … … 217 217 return getRegistry(userspace).getMDProfile(profileId); 218 218 } 219 219 220 220 @GET 221 221 @Path("/components/usage/{componentId}") … … 227 227 List<ComponentDescription> components = registry.getUsageInComponents(componentId); 228 228 List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId); 229 229 230 230 LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId 231 231 + " (" + (System.currentTimeMillis() - start) + " millisecs)"); 232 232 233 233 List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size()); 234 234 usages.addAll(components); 235 235 usages.addAll(profiles); 236 236 237 237 return usages; 238 238 } catch (ComponentRegistryException e) { … … 241 241 } 242 242 } 243 243 244 244 @GET 245 245 @Path("/profiles/{profileId}/comments") … … 252 252 return comments; 253 253 } 254 254 255 255 @GET 256 256 @Path("/components/{componentId}/comments") … … 263 263 return comments; 264 264 } 265 265 266 266 @GET 267 267 @Path("/profiles/{profileId}/comments/{commentId}") … … 271 271 return getRegistry(userspace).getSpecifiedCommentInProfile(profileId, commentId); 272 272 } 273 273 274 274 @GET 275 275 @Path("/components/{componentId}/comments/{commentId}") … … 299 299 } 300 300 } 301 301 302 302 @POST 303 303 @Path("/profiles/{profileId}/comments/{commentId}") … … 310 310 } 311 311 } 312 312 313 313 @POST 314 314 @Path("/components/{componentId}/comments/{commentId}") … … 321 321 } 322 322 } 323 323 324 324 @POST 325 325 @Path("/profiles/{profileId}/publish") … … 345 345 } 346 346 } 347 347 348 348 @POST 349 349 @Path("/profiles/{profileId}/update") … … 370 370 return Response.status(Status.UNAUTHORIZED).entity(ex.getMessage()).build(); 371 371 } 372 372 373 373 } 374 374 … … 392 392 } 393 393 } 394 394 395 395 @POST 396 396 @Path("/components/{componentId}/publish") … … 417 417 } 418 418 } 419 419 420 420 @POST 421 421 @Path("/components/{componentId}/update") … … 442 442 } 443 443 } 444 444 445 445 private void updateDescription(AbstractDescription desc, String name, String description, String domainName, String group) { 446 446 desc.setName(name); … … 450 450 desc.setRegistrationDate(AbstractDescription.createNewDate()); 451 451 } 452 452 453 453 @DELETE 454 454 @Path("/components/{componentId}") … … 476 476 return Response.ok().build(); 477 477 } 478 478 479 479 @DELETE 480 480 @Path("/profiles/{profileId}") … … 501 501 return Response.ok().build(); 502 502 } 503 503 504 504 @DELETE 505 505 @Path("/profiles/{profileId}/comments/{commentId}") … … 532 532 return Response.ok().build(); 533 533 } 534 534 535 535 @DELETE 536 536 @Path("/components/{componentId}/comments/{commentId}") … … 563 563 return Response.ok().build(); 564 564 } 565 565 566 566 @GET 567 567 @Path("/profiles/{profileId}/{rawType}") … … 578 578 checkAndThrowDescription(desc, profileId); 579 579 String fileName = desc.getName() + "." + rawType; 580 580 581 581 if ("xml".equalsIgnoreCase(rawType)) { 582 582 result = new StreamingOutput() { 583 583 584 584 @Override 585 585 public void write(OutputStream output) throws IOException, WebApplicationException { … … 594 594 } else if ("xsd".equalsIgnoreCase(rawType)) { 595 595 result = new StreamingOutput() { 596 596 597 597 @Override 598 598 public void write(OutputStream output) throws IOException, WebApplicationException { … … 615 615 } 616 616 } 617 617 618 618 private void checkAndThrowDescription(AbstractDescription desc, String id) { 619 619 if (desc == null) { … … 621 621 } 622 622 } 623 623 624 624 private Response createDownloadResponse(StreamingOutput result, String fileName) { 625 625 //Making response so it triggers browsers native save as dialog. … … 627 627 "attachment; filename=\"" + fileName + "\"").entity(result).build(); 628 628 return response; 629 630 } 631 629 630 } 631 632 632 @POST 633 633 @Path("/profiles") … … 653 653 } 654 654 } 655 655 656 656 @POST 657 657 @Path("/components") … … 677 677 } 678 678 } 679 679 680 680 @POST 681 681 @Path("/components/{componentId}/comments") … … 703 703 } 704 704 } 705 705 706 706 @POST 707 707 @Path("/profiles/{profileId}/comments") … … 729 729 } 730 730 } 731 731 732 732 @GET 733 733 @Path("/pingSession") … … 744 744 return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build(); 745 745 } 746 746 747 747 private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace, 748 748 RegisterAction action) { … … 779 779 } 780 780 response.setIsProfile(desc.isProfile()); 781 LOG.info("Registration of {} successful: {}", response.getDescription().getId(), response.isRegistered()); 781 if (response.isRegistered()) { 782 LOG.info("Registration of {} was successful", response.getDescription().getId()); 783 } 782 784 return Response.ok(response).build(); 783 785 } finally { … … 789 791 } 790 792 } 791 793 792 794 private Response registerComment(InputStream input, ComponentRegistry registry, boolean userspace, 793 795 AbstractDescription description, Principal principal, UserCredentials userCredentials) { … … 809 811 } 810 812 } 811 813 812 814 int returnCode = registry.registerComment(com, principal.getName()); 813 815 if (returnCode == 0) { … … 835 837 } 836 838 } 837 839 838 840 private ComponentDescription createNewComponentDescription() { 839 841 ComponentDescription desc = ComponentDescription.createNewDescription(); … … 841 843 return desc; 842 844 } 843 845 844 846 private ProfileDescription createNewProfileDescription() { 845 847 ProfileDescription desc = ProfileDescription.createNewDescription(); … … 847 849 return desc; 848 850 } 849 851 850 852 private Comment createNewComment() { 851 853 Comment com = Comment.createANewComment(); 852 854 return com; 853 855 } 854 856 855 857 private String createXlink(String id) { 856 858 URI uri = uriInfo.getRequestUriBuilder().path(id).build(); 857 859 return uri.toString(); 858 860 } 859 861 860 862 private void validate(RegisterResponse response, Validator... validators) { 861 863 for (Validator validator : validators) { … … 867 869 } 868 870 } 869 871 870 872 private void validateComment(CommentResponse response, Validator... validators) { 871 873 for (Validator validator : validators) {
Note: See TracChangeset
for help on using the changeset viewer.