Changeset 1993
- Timestamp:
- 06/18/12 15:24:30 (12 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryFactory.java
r1698 r1993 15 15 List<ComponentRegistry> getAllUserRegistries(); 16 16 17 ComponentRegistry getComponentRegistry(boolean userspace, UserCredentials credentials); 17 /** 18 * Gets the specified registry 19 * 20 * @param status status of the registry 21 * @param owner owner of the registry. Passing null will assume the authenticated user as a {@link OwnerUser} 22 * @param credentials credentials that authenticate user, can be left null if requested registry has a public status 23 * @return 24 */ 25 ComponentRegistry getComponentRegistry(ComponentStatus status, Owner owner, UserCredentials credentials) throws UserUnauthorizedException; 18 26 19 ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, String userId);27 ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, ComponentStatus status, Owner owner); 20 28 21 29 ComponentRegistry getPublicRegistry(); -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.java
r1778 r1993 29 29 import clarin.cmdi.componentregistry.ComponentRegistryException; 30 30 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 31 import clarin.cmdi.componentregistry.ComponentStatus; 31 32 import clarin.cmdi.componentregistry.impl.database.AdminRegistry; 32 33 import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao; … … 275 276 DefaultMutableTreeNode componentsNode = new DefaultMutableTreeNode(new DisplayDataNode("Components", false)); 276 277 parent.add(componentsNode); 277 add(componentsNode, registry.getComponentDescriptions(), false, registry. isPublic());278 add(componentsNode, registry.getComponentDescriptions(), false, registry.getStatus()); 278 279 279 280 DefaultMutableTreeNode profilesNode = new DefaultMutableTreeNode(new DisplayDataNode("Profiles", false)); 280 281 parent.add(profilesNode); 281 add(profilesNode, registry.getProfileDescriptions(), false, registry. isPublic());282 add(profilesNode, registry.getProfileDescriptions(), false, registry.getStatus()); 282 283 283 284 DefaultMutableTreeNode deletedCompNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Components", true)); … … 285 286 286 287 List<ComponentDescription> deletedComponentDescriptions = registry.getDeletedComponentDescriptions(); 287 add(deletedCompNode, deletedComponentDescriptions, true, registry. isPublic());288 add(deletedCompNode, deletedComponentDescriptions, true, registry.getStatus()); 288 289 289 290 DefaultMutableTreeNode deletedProfNode = new DefaultMutableTreeNode(new DisplayDataNode("Deleted Profiles", true)); 290 291 parent.add(deletedProfNode); 291 292 List<ProfileDescription> deletedProfileDescriptions = registry.getDeletedProfileDescriptions(); 292 add(deletedProfNode, deletedProfileDescriptions, true, registry. isPublic());293 } 294 295 private void add(DefaultMutableTreeNode parent, List<? extends AbstractDescription> descs, boolean isDeleted, boolean isPublic) {293 add(deletedProfNode, deletedProfileDescriptions, true, registry.getStatus()); 294 } 295 296 private void add(DefaultMutableTreeNode parent, List<? extends AbstractDescription> descs, boolean isDeleted, ComponentStatus status) { 296 297 for (AbstractDescription desc : descs) { 297 DefaultMutableTreeNode child = new DefaultMutableTreeNode(new DisplayDataNode(desc.getName(), isDeleted, desc, isPublic));298 DefaultMutableTreeNode child = new DefaultMutableTreeNode(new DisplayDataNode(desc.getName(), isDeleted, desc, status)); 298 299 parent.add(child); 299 300 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/CMDItemInfo.java
r1364 r1993 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import clarin.cmdi.componentregistry.ComponentStatus; 3 4 import java.io.Serializable; 4 5 … … 92 93 } 93 94 94 95 public boolean isInUserWorkSpace() {96 return !displayNode.isPublic();95 96 public ComponentStatus getStatus() { 97 return displayNode.getStatus(); 97 98 } 98 99 99 100 public void setForceUpdate(boolean forceUpdate) { 100 101 this.forceUpdate = forceUpdate; -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/DisplayDataNode.java
r1364 r1993 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import clarin.cmdi.componentregistry.ComponentStatus; 3 4 import java.io.Serializable; 4 5 … … 11 12 private final boolean isDeleted; 12 13 private AbstractDescription desc; 13 private final boolean isPublic;14 private final ComponentStatus status; 14 15 15 16 public DisplayDataNode(String name, boolean isDeleted) { 16 this(name, isDeleted, null, false); 17 // TODO: what is sensible default status? 18 this(name, isDeleted, null, ComponentStatus.DEVELOPMENT); 17 19 } 18 20 19 public DisplayDataNode(String name, boolean isDeleted, AbstractDescription desc, boolean isPublic) {20 21 22 23 this.isPublic = isPublic;21 public DisplayDataNode(String name, boolean isDeleted, AbstractDescription desc, ComponentStatus status) { 22 this.name = name; 23 this.isDeleted = isDeleted; 24 this.desc = desc; 25 this.status = status; 24 26 } 25 27 26 28 /** 27 29 * Can be null for non leaves. 30 * 28 31 * @return 29 32 */ 30 33 public AbstractDescription getDescription() { 31 34 return desc; 32 35 } 33 36 34 37 public boolean isDeleted() { 35 38 return isDeleted; 36 39 } 37 40 38 41 @Override 39 42 public String toString() { 40 43 return name; 41 44 } 42 45 43 public boolean isPublic() {44 return isPublic;46 public ComponentStatus getStatus() { 47 return status; 45 48 } 46 47 49 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AdminRegistry.java
r1372 r1993 14 14 import clarin.cmdi.componentregistry.ComponentRegistryException; 15 15 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 16 import clarin.cmdi.componentregistry.ComponentStatus; 16 17 import clarin.cmdi.componentregistry.DeleteFailedException; 17 18 import clarin.cmdi.componentregistry.MDMarshaller; 19 import clarin.cmdi.componentregistry.OwnerUser; 18 20 import clarin.cmdi.componentregistry.UserUnauthorizedException; 19 21 import clarin.cmdi.componentregistry.components.CMDComponentSpec; … … 25 27 26 28 public class AdminRegistry { 29 27 30 private final static Logger LOG = LoggerFactory.getLogger(AdminRegistry.class); 28 29 31 private ComponentRegistryFactory componentRegistryFactory; 30 32 private ProfileDescriptionDao profileDescriptionDao; … … 118 120 private ComponentRegistry getRegistry(Principal userPrincipal, AbstractDescription desc, CMDItemInfo info) { 119 121 ComponentRegistry registry = componentRegistryFactory.getPublicRegistry(); 120 if (info.isInUserWorkSpace()) { 121 registry = componentRegistryFactory.getOtherUserComponentRegistry(userPrincipal, desc.getUserId()); 122 //TODO: More generic check 123 if (info.getStatus() == ComponentStatus.DEVELOPMENT /* || info.getStatus() == ComponentStatus.PRIVATE */) { 124 registry = componentRegistryFactory.getOtherUserComponentRegistry(userPrincipal, info.getStatus(), new OwnerUser(Integer.parseInt(desc.getUserId()))); 122 125 } 123 126 return registry; 124 127 } 125 126 128 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImpl.java
r1992 r1993 1 1 package clarin.cmdi.componentregistry.impl.database; 2 3 import java.security.Principal;4 import java.util.ArrayList;5 import java.util.List;6 7 import org.slf4j.Logger;8 import org.slf4j.LoggerFactory;9 import org.springframework.beans.factory.annotation.Autowired;10 import org.springframework.dao.DataAccessException;11 2 12 3 import clarin.cmdi.componentregistry.ComponentRegistry; … … 14 5 import clarin.cmdi.componentregistry.ComponentStatus; 15 6 import clarin.cmdi.componentregistry.Configuration; 7 import clarin.cmdi.componentregistry.Owner; 16 8 import clarin.cmdi.componentregistry.OwnerUser; 17 9 import clarin.cmdi.componentregistry.UserCredentials; 10 import clarin.cmdi.componentregistry.UserUnauthorizedException; 18 11 import clarin.cmdi.componentregistry.model.RegistryUser; 12 import java.security.Principal; 13 import java.util.ArrayList; 14 import java.util.List; 15 import org.slf4j.Logger; 16 import org.slf4j.LoggerFactory; 17 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.dao.DataAccessException; 19 19 20 20 /** … … 53 53 54 54 @Override 55 public ComponentRegistry getComponentRegistry(boolean userspace, UserCredentials credentials) { 56 ComponentRegistry result = null; 57 if (userspace) { 55 public ComponentRegistry getComponentRegistry(ComponentStatus status, Owner owner, UserCredentials credentials) throws UserUnauthorizedException { 56 switch (status) { 57 case DEVELOPMENT: 58 return getDevelopmentRegistry(owner, credentials); 59 case PUBLIC: 60 return getPublicRegistry(); 61 default: 62 // TODO: Add support for other status types 63 throw new UnsupportedOperationException("Unsupported component status" + status); 64 } 65 } 66 67 private ComponentRegistry getDevelopmentRegistry(Owner owner, UserCredentials credentials) throws IllegalArgumentException, DataAccessException, UserUnauthorizedException { 68 if (owner == null || owner instanceof OwnerUser) { 58 69 RegistryUser user = getOrCreateUser(credentials); 59 70 if (user != null) { 71 if (owner != null && !user.getId().equals(owner.getId())) { 72 throw new UserUnauthorizedException("User cannot access other user's development registry"); 73 } 74 60 75 try { 61 re sult =getNewComponentRegistryForUser(user.getId());76 return getNewComponentRegistryForUser(user.getId()); 62 77 } catch (DataAccessException ex) { 63 78 LOG.error("Could not retrieve or create user", ex); … … 68 83 } 69 84 } else { 70 result = getPublicRegistry(); 85 // TODO: Support group owners 86 throw new UnsupportedOperationException("Group owners not supported"); 71 87 } 72 return result;73 88 } 74 89 75 90 @Override 76 public ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, String userId) {91 public ComponentRegistry getOtherUserComponentRegistry(Principal adminPrincipal, ComponentStatus status, Owner owner) { 77 92 try { 78 RegistryUser user = userDao.getById(Integer.parseInt(userId)); 93 RegistryUser user; 94 if (owner instanceof OwnerUser) { 95 user = userDao.getById(owner.getId()); 96 } else { 97 // TODO: Implement for groups 98 throw new UnsupportedOperationException("Groups not implemented yet"); 99 } 79 100 ComponentRegistry result = null; 80 101 if (user != null) { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r1894 r1993 4 4 import clarin.cmdi.componentregistry.ComponentRegistryException; 5 5 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 6 import clarin.cmdi.componentregistry.ComponentStatus; 6 7 import clarin.cmdi.componentregistry.DeleteFailedException; 8 import clarin.cmdi.componentregistry.Owner; 7 9 import clarin.cmdi.componentregistry.UserCredentials; 8 10 import clarin.cmdi.componentregistry.UserUnauthorizedException; … … 48 50 @Path("/registry") 49 51 public class ComponentRegistryRestService { 50 52 51 53 @Context 52 54 private UriInfo uriInfo; … … 65 67 @Inject(value = "componentRegistryFactory") 66 68 private ComponentRegistryFactory componentRegistryFactory; 67 68 private ComponentRegistry getRegistry(boolean userspace) { 69 70 /** 71 * Converts userspace boolean to component status. Temporary solution!!! 72 * 73 * TODO: Replace all calls to getRegistry that use this by calls using ComponentStatus 74 * @param userSpace 75 * @return 76 * @deprecated All calls should go directly to {@link #getRegistry(clarin.cmdi.componentregistry.ComponentStatus)} 77 */ 78 @Deprecated 79 private static ComponentStatus getStatus(boolean userSpace) { 80 if (userSpace) { 81 return ComponentStatus.DEVELOPMENT; 82 } else { 83 return ComponentStatus.PUBLIC; 84 } 85 } 86 87 private ComponentRegistry getRegistry(ComponentStatus status) { 69 88 Principal userPrincipal = security.getUserPrincipal(); 70 89 UserCredentials userCredentials = getUserCredentials(userPrincipal); 71 return getRegistry(userspace, userCredentials); 72 } 73 74 private ComponentRegistry getRegistry(boolean userspace, UserCredentials userCredentials) { 75 return componentRegistryFactory.getComponentRegistry(userspace, userCredentials); 90 return getRegistry(status, null, userCredentials); 91 } 92 93 private ComponentRegistry getRegistry(ComponentStatus status, Owner owner, UserCredentials userCredentials) { 94 try { 95 return componentRegistryFactory.getComponentRegistry(status, owner, userCredentials); 96 } catch (UserUnauthorizedException uuEx) { 97 //TODO: Throw actual exception and catch nicely 98 throw new RuntimeException("Cannot access requested registry", uuEx); 99 } 76 100 } 77 101 … … 88 112 return principal; 89 113 } 90 114 91 115 private UserCredentials getUserCredentials(Principal userPrincipal) { 92 116 UserCredentials userCredentials = null; … … 96 120 return userCredentials; 97 121 } 98 122 99 123 @GET 100 124 @Path("/components") … … 102 126 public List<ComponentDescription> getRegisteredComponents(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException { 103 127 long start = System.currentTimeMillis(); 104 List<ComponentDescription> components = getRegistry( userspace).getComponentDescriptions();128 List<ComponentDescription> components = getRegistry(getStatus(userspace)).getComponentDescriptions(); 105 129 LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start) 106 130 + " millisecs)"); 107 131 return components; 108 132 } 109 133 110 134 @GET 111 135 @Path("/profiles") … … 114 138 @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException { 115 139 long start = System.currentTimeMillis(); 116 140 117 141 List<ProfileDescription> profiles; 118 142 if (metadataEditor) { 119 profiles = getRegistry( userspace).getProfileDescriptionsForMetadaEditor();143 profiles = getRegistry(getStatus(userspace)).getProfileDescriptionsForMetadaEditor(); 120 144 } else { 121 profiles = getRegistry( userspace).getProfileDescriptions();122 } 123 145 profiles = getRegistry(getStatus(userspace)).getProfileDescriptions(); 146 } 147 124 148 LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start) 125 149 + " millisecs)"); 126 150 return profiles; 127 151 } 128 152 129 153 @GET 130 154 @Path("/components/{componentId}") … … 133 157 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException { 134 158 LOG.info("Component with id: " + componentId + " is requested."); 135 CMDComponentSpec mdComponent = getRegistry( userspace).getMDComponent(componentId);159 CMDComponentSpec mdComponent = getRegistry(getStatus(userspace)).getMDComponent(componentId); 136 160 if (mdComponent == null) { 137 161 return Response.status(Status.NOT_FOUND).build(); … … 140 164 } 141 165 } 142 166 143 167 @GET 144 168 @Path("/components/{componentId}/{rawType}") … … 157 181 if ("xml".equalsIgnoreCase(rawType)) { 158 182 result = new StreamingOutput() { 159 183 160 184 @Override 161 185 public void write(OutputStream output) throws IOException, WebApplicationException { … … 170 194 } else if ("xsd".equalsIgnoreCase(rawType)) { 171 195 result = new StreamingOutput() { 172 196 173 197 @Override 174 198 public void write(OutputStream output) throws IOException, WebApplicationException { … … 179 203 throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build()); 180 204 } 181 205 182 206 } 183 207 }; … … 192 216 } 193 217 } 194 218 195 219 public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) throws ComponentRegistryException { 196 220 AbstractDescription desc = null; 197 ComponentRegistry result = getRegistry( false);221 ComponentRegistry result = getRegistry(getStatus(false)); 198 222 desc = clos.getDescription(result, id); 199 223 if (desc == null) { … … 209 233 return result; 210 234 } 211 235 212 236 @GET 213 237 @Path("/profiles/{profileId}") … … 216 240 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException { 217 241 LOG.info("Profile with id: " + profileId + " is requested."); 218 CMDComponentSpec mdProfile = getRegistry( userspace).getMDProfile(profileId);242 CMDComponentSpec mdProfile = getRegistry(getStatus(userspace)).getMDProfile(profileId); 219 243 if (mdProfile == null) { 220 244 return Response.status(Status.NOT_FOUND).build(); … … 223 247 } 224 248 } 225 249 226 250 @GET 227 251 @Path("/components/usage/{componentId}") … … 230 254 try { 231 255 final long start = System.currentTimeMillis(); 232 ComponentRegistry registry = getRegistry( userspace);256 ComponentRegistry registry = getRegistry(getStatus(userspace)); 233 257 List<ComponentDescription> components = registry.getUsageInComponents(componentId); 234 258 List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId); 235 259 236 260 LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId 237 261 + " (" + (System.currentTimeMillis() - start) + " millisecs)"); 238 262 239 263 List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size()); 240 264 usages.addAll(components); 241 265 usages.addAll(profiles); 242 266 243 267 return usages; 244 268 } catch (ComponentRegistryException e) { … … 247 271 } 248 272 } 249 273 250 274 @GET 251 275 @Path("/profiles/{profileId}/comments") … … 254 278 long start = System.currentTimeMillis(); 255 279 final Principal principal = security.getUserPrincipal(); 256 List<Comment> comments = getRegistry( userspace).getCommentsInProfile(profileId, principal);280 List<Comment> comments = getRegistry(getStatus(userspace)).getCommentsInProfile(profileId, principal); 257 281 LOG.info("Releasing " + comments.size() + " registered comments in Profile into the world (" + (System.currentTimeMillis() - start) 258 282 + " millisecs)"); 259 283 return comments; 260 284 } 261 285 262 286 @GET 263 287 @Path("/components/{componentId}/comments") … … 266 290 long start = System.currentTimeMillis(); 267 291 final Principal principal = security.getUserPrincipal(); 268 List<Comment> comments = getRegistry( userspace).getCommentsInComponent(componentId, principal);292 List<Comment> comments = getRegistry(getStatus(userspace)).getCommentsInComponent(componentId, principal); 269 293 LOG.info("Releasing " + comments.size() + " registered comments in Component into the world (" + (System.currentTimeMillis() - start) 270 294 + " millisecs)"); 271 295 return comments; 272 296 } 273 297 274 298 @GET 275 299 @Path("/profiles/{profileId}/comments/{commentId}") … … 278 302 LOG.info(" Comments of component with id" + commentId + " are requested."); 279 303 final Principal principal = security.getUserPrincipal(); 280 return getRegistry( userspace).getSpecifiedCommentInProfile(profileId, commentId, principal);281 } 282 304 return getRegistry(getStatus(userspace)).getSpecifiedCommentInProfile(profileId, commentId, principal); 305 } 306 283 307 @GET 284 308 @Path("/components/{componentId}/comments/{commentId}") … … 287 311 LOG.info(" Comments of component with id" + commentId + " are requested."); 288 312 final Principal principal = security.getUserPrincipal(); 289 return getRegistry( userspace).getSpecifiedCommentInComponent(componentId, commentId, principal);313 return getRegistry(getStatus(userspace)).getSpecifiedCommentInComponent(componentId, commentId, principal); 290 314 } 291 315 … … 309 333 } 310 334 } 311 335 312 336 @POST 313 337 @Path("/profiles/{profileId}/comments/{commentId}") … … 320 344 } 321 345 } 322 346 323 347 @POST 324 348 @Path("/components/{componentId}/comments/{commentId}") … … 331 355 } 332 356 } 333 357 334 358 @POST 335 359 @Path("/profiles/{profileId}/publish") … … 340 364 try { 341 365 Principal principal = checkAndGetUserPrincipal(); 342 ProfileDescription desc = getRegistry( true).getProfileDescription(profileId);366 ProfileDescription desc = getRegistry(getStatus(true)).getProfileDescription(profileId); 343 367 if (desc != null) { 344 368 updateDescription(desc, name, description, domainName, group); … … 355 379 } 356 380 } 357 381 358 382 @POST 359 383 @Path("/profiles/{profileId}/update") … … 366 390 Principal principal = checkAndGetUserPrincipal(); 367 391 UserCredentials userCredentials = getUserCredentials(principal); 368 ProfileDescription desc = getRegistry( userspace).getProfileDescription(profileId);392 ProfileDescription desc = getRegistry(getStatus(userspace)).getProfileDescription(profileId); 369 393 if (desc != null) { 370 394 updateDescription(desc, name, description, domainName, group); … … 380 404 return Response.status(Status.UNAUTHORIZED).entity(ex.getMessage()).build(); 381 405 } 382 406 383 407 } 384 408 … … 402 426 } 403 427 } 404 428 405 429 @POST 406 430 @Path("/components/{componentId}/publish") … … 412 436 try { 413 437 Principal principal = checkAndGetUserPrincipal(); 414 ComponentDescription desc = getRegistry(true).getComponentDescription(componentId); 438 // TODO: Get status from parameter 439 ComponentDescription desc = getRegistry(getStatus(true)).getComponentDescription(componentId); 415 440 if (desc != null) { 416 441 updateDescription(desc, name, description, domainName, group); … … 427 452 } 428 453 } 429 454 430 455 @POST 431 456 @Path("/components/{componentId}/update") … … 437 462 try { 438 463 Principal principal = checkAndGetUserPrincipal(); 439 ComponentDescription desc = getRegistry( userspace).getComponentDescription(componentId);464 ComponentDescription desc = getRegistry(getStatus(userspace)).getComponentDescription(componentId); 440 465 if (desc != null) { 441 466 updateDescription(desc, name, description, domainName, group); … … 452 477 } 453 478 } 454 479 455 480 private void updateDescription(AbstractDescription desc, String name, String description, String domainName, String group) { 456 481 desc.setName(name); … … 460 485 desc.setRegistrationDate(AbstractDescription.createNewDate()); 461 486 } 462 487 463 488 @DELETE 464 489 @Path("/components/{componentId}") … … 467 492 try { 468 493 Principal principal = checkAndGetUserPrincipal(); 469 ComponentRegistry registry = getRegistry( userspace);494 ComponentRegistry registry = getRegistry(getStatus(userspace)); 470 495 LOG.info("Component with id: " + componentId + " set for deletion."); 471 496 registry.deleteMDComponent(componentId, principal, false); … … 486 511 return Response.ok().build(); 487 512 } 488 513 489 514 @DELETE 490 515 @Path("/profiles/{profileId}") … … 494 519 Principal principal = checkAndGetUserPrincipal(); 495 520 LOG.info("Profile with id: " + profileId + " set for deletion."); 496 getRegistry( userspace).deleteMDProfile(profileId, principal);521 getRegistry(getStatus(userspace)).deleteMDProfile(profileId, principal); 497 522 } catch (DeleteFailedException e) { 498 523 LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage()); … … 511 536 return Response.ok().build(); 512 537 } 513 538 514 539 @DELETE 515 540 @Path("/profiles/{profileId}/comments/{commentId}") … … 518 543 try { 519 544 final Principal principal = checkAndGetUserPrincipal(); 520 final ComponentRegistry registry = getRegistry( userspace);545 final ComponentRegistry registry = getRegistry(getStatus(userspace)); 521 546 final Comment comment = registry.getSpecifiedCommentInProfile(profileId, commentId, principal); 522 547 if (comment != null && profileId.equals(comment.getProfileDescriptionId())) { … … 542 567 return Response.ok().build(); 543 568 } 544 569 545 570 @DELETE 546 571 @Path("/components/{componentId}/comments/{commentId}") … … 549 574 try { 550 575 final Principal principal = checkAndGetUserPrincipal(); 551 final ComponentRegistry registry = getRegistry( userspace);576 final ComponentRegistry registry = getRegistry(getStatus(userspace)); 552 577 final Comment comment = registry.getSpecifiedCommentInComponent(componentId, commentId, principal); 553 578 if (comment != null && componentId.equals(comment.getComponentDescriptionId())) { … … 573 598 return Response.ok().build(); 574 599 } 575 600 576 601 @GET 577 602 @Path("/profiles/{profileId}/{rawType}") … … 588 613 checkAndThrowDescription(desc, profileId); 589 614 String fileName = desc.getName() + "." + rawType; 590 615 591 616 if ("xml".equalsIgnoreCase(rawType)) { 592 617 result = new StreamingOutput() { 593 618 594 619 @Override 595 620 public void write(OutputStream output) throws IOException, WebApplicationException { … … 604 629 } else if ("xsd".equalsIgnoreCase(rawType)) { 605 630 result = new StreamingOutput() { 606 631 607 632 @Override 608 633 public void write(OutputStream output) throws IOException, WebApplicationException { … … 625 650 } 626 651 } 627 652 628 653 private void checkAndThrowDescription(AbstractDescription desc, String id) { 629 654 if (desc == null) { … … 631 656 } 632 657 } 633 658 634 659 private Response createDownloadResponse(StreamingOutput result, String fileName) { 635 660 //Making response so it triggers browsers native save as dialog. … … 637 662 "attachment; filename=\"" + fileName + "\"").entity(result).build(); 638 663 return response; 639 640 } 641 664 665 } 666 642 667 @POST 643 668 @Path("/profiles") … … 663 688 } 664 689 } 665 690 666 691 @POST 667 692 @Path("/components") … … 687 712 } 688 713 } 689 714 690 715 @POST 691 716 @Path("/components/{componentId}/comments") … … 700 725 throw new UserUnauthorizedException("Cannot materialize authenticated user"); 701 726 } 702 ComponentRegistry registry = getRegistry(userspace, userCredentials); 727 // TODO: Add user/group param 728 ComponentRegistry registry = getRegistry(getStatus(userspace), null, userCredentials); 703 729 ComponentDescription description = registry.getComponentDescription(componentId); 704 730 if (description != null) { … … 713 739 } 714 740 } 715 741 716 742 @POST 717 743 @Path("/profiles/{profileId}/comments") … … 726 752 throw new UserUnauthorizedException("Cannot materialize authenticated user"); 727 753 } 728 ComponentRegistry registry = getRegistry(userspace, userCredentials); 754 // TODO: Add user/group param 755 ComponentRegistry registry = getRegistry(getStatus(userspace), null, userCredentials); 729 756 ProfileDescription description = registry.getProfileDescription(profileId); 730 757 if (description != null) { … … 739 766 } 740 767 } 741 768 742 769 @GET 743 770 @Path("/pingSession") … … 754 781 return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build(); 755 782 } 756 783 757 784 private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace, 758 785 RegisterAction action) { 759 786 try { 760 ComponentRegistry registry = getRegistry(userspace, userCredentials); 787 // TODO: Add user/group param 788 ComponentRegistry registry = getRegistry(getStatus(userspace), null, userCredentials); 761 789 DescriptionValidator descriptionValidator = new DescriptionValidator(desc); 762 MDValidator validator = new MDValidator(input, desc, registry, getRegistry( true), componentRegistryFactory.getPublicRegistry());790 MDValidator validator = new MDValidator(input, desc, registry, getRegistry(getStatus(true)), componentRegistryFactory.getPublicRegistry()); 763 791 RegisterResponse response = new RegisterResponse(); 764 792 response.setIsInUserSpace(userspace); … … 798 826 } 799 827 } 800 828 801 829 private Response registerComment(InputStream input, ComponentRegistry registry, boolean userspace, 802 830 AbstractDescription description, Principal principal, UserCredentials userCredentials) { … … 818 846 } 819 847 } 820 848 821 849 int returnCode = registry.registerComment(com, principal.getName()); 822 850 if (returnCode == 0) { … … 844 872 } 845 873 } 846 874 847 875 private ComponentDescription createNewComponentDescription() { 848 876 ComponentDescription desc = ComponentDescription.createNewDescription(); … … 850 878 return desc; 851 879 } 852 880 853 881 private ProfileDescription createNewProfileDescription() { 854 882 ProfileDescription desc = ProfileDescription.createNewDescription(); … … 856 884 return desc; 857 885 } 858 886 859 887 private Comment createNewComment() { 860 888 Comment com = Comment.createANewComment(); 861 889 return com; 862 890 } 863 891 864 892 private String createXlink(String id) { 865 893 URI uri = uriInfo.getRequestUriBuilder().path(id).build(); 866 894 return uri.toString(); 867 895 } 868 896 869 897 private void validate(RegisterResponse response, Validator... validators) { 870 898 for (Validator validator : validators) { … … 876 904 } 877 905 } 878 906 879 907 private void validateComment(CommentResponse response, Validator... validators) { 880 908 for (Validator validator : validators) { -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/frontend/CMDItemInfoTest.java
r1364 r1993 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import clarin.cmdi.componentregistry.ComponentStatus; 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertFalse; … … 14 15 @Test 15 16 public void testGetUserDir() throws Exception { 16 17 18 info.setDataNode(new DisplayDataNode("test", false, createDescription(), false));19 20 21 22 23 assertTrue(info.isInUserWorkSpace());24 25 info.setDataNode(new DisplayDataNode("test", true, createDescription(), false));26 27 28 29 30 assertTrue(info.isInUserWorkSpace());31 32 info.setDataNode(new DisplayDataNode("test", false, createDescription(), true));33 34 35 36 assertFalse(info.isInUserWorkSpace());37 38 39 40 41 42 43 info.setDataNode(new DisplayDataNode("test", true, createDescription(), true));44 45 46 47 assertFalse(info.isInUserWorkSpace());48 49 50 51 52 53 54 17 CMDItemInfo info = new CMDItemInfo(); 18 //info.setDataNode(new FileNode(createFile("users/user1/components/c_123/description.xml"), false)); 19 info.setDataNode(new DisplayDataNode("test", false, createDescription(), ComponentStatus.DEVELOPMENT)); 20 assertTrue(info.isDeletable()); 21 assertFalse(info.isUndeletable()); 22 assertTrue(info.isEditable()); 23 assertFalse(info.getDataNode().isDeleted()); 24 assertEquals(ComponentStatus.DEVELOPMENT, info.getStatus()); 25 //info.setDataNode(new FileNode(createFile("users/user1/components/deleted/c_123/description.xml"), true)); 26 info.setDataNode(new DisplayDataNode("test", true, createDescription(), ComponentStatus.DEVELOPMENT)); 27 assertFalse(info.isDeletable()); 28 assertTrue(info.isUndeletable()); 29 assertTrue(info.isEditable()); 30 assertTrue(info.getDataNode().isDeleted()); 31 assertEquals(ComponentStatus.DEVELOPMENT, info.getStatus()); 32 //info.setDataNode(new FileNode(createFile("components/c_123/description.xml"), false)); 33 info.setDataNode(new DisplayDataNode("test", false, createDescription(), ComponentStatus.PUBLIC)); 34 assertTrue(info.isDeletable()); 35 assertFalse(info.isUndeletable()); 36 assertTrue(info.isEditable()); 37 assertEquals(ComponentStatus.PUBLIC, info.getStatus()); 38 //info.setDataNode(new FileNode(createFile("components/c_123/"), false)); 39 info.setDataNode(new DisplayDataNode("test", false)); 40 assertFalse(info.isDeletable()); 41 assertFalse(info.isUndeletable()); 42 assertFalse(info.isEditable()); 43 //info.setDataNode(new FileNode(createFile("components/deleted/c_123/description.xml"), true)); 44 info.setDataNode(new DisplayDataNode("test", true, createDescription(), ComponentStatus.PUBLIC)); 45 assertFalse(info.isDeletable()); 46 assertTrue(info.isUndeletable()); 47 assertTrue(info.isEditable()); 48 assertEquals(ComponentStatus.PUBLIC, info.getStatus()); 49 assertTrue(info.getDescription().startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<profileDescription")); 50 //info.setDataNode(new FileNode(createFile("components/deleted/c_123/"), true)); 51 info.setDataNode(new DisplayDataNode("test", true)); 52 assertFalse(info.isDeletable()); 53 assertFalse(info.isUndeletable()); 54 assertFalse(info.isEditable()); 55 assertEquals("", info.getDescription()); 55 56 } 56 57 57 58 private AbstractDescription createDescription() { 58 59 return ProfileDescription.createNewDescription(); 59 60 } 60 61 61 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AdminRegistryTest.java
r1603 r1993 17 17 import clarin.cmdi.componentregistry.ComponentRegistry; 18 18 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 19 import clarin.cmdi.componentregistry.ComponentStatus; 19 20 import clarin.cmdi.componentregistry.DeleteFailedException; 20 21 import clarin.cmdi.componentregistry.frontend.CMDItemInfo; … … 28 29 @RunWith(SpringJUnit4ClassRunner.class) 29 30 @ContextConfiguration(locations = {"/applicationContext.xml"}) 30 public class AdminRegistryTest 31 31 public class AdminRegistryTest { 32 32 33 @Autowired 33 34 private ComponentDescriptionDao componentDescriptionDao; … … 37 38 private ComponentRegistryFactory componentRegistryFactory; 38 39 private static final Principal PRINCIPAL_ADMIN = DummyPrincipal.DUMMY_ADMIN_PRINCIPAL; 39 40 40 @Autowired 41 41 private JdbcTemplate jdbcTemplate; 42 42 43 43 @Before 44 44 public void init() { … … 48 48 @Test 49 49 public void testForceUpdate() throws Exception { 50 51 52 53 54 55 56 57 58 59 50 ComponentRegistry testRegistry = componentRegistryFactory.getPublicRegistry(); 51 String content1 = ""; 52 content1 += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 53 content1 += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 54 content1 += " <Header/>\n"; 55 content1 += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; 56 content1 += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 57 content1 += " </CMD_Component>\n"; 58 content1 += "</CMD_ComponentSpec>\n"; 59 ComponentDescription compDesc1 = RegistryTestHelper.addComponent(testRegistry, "XXX1", content1); 60 60 61 62 63 64 65 66 67 68 69 70 61 String content2 = ""; 62 content2 += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 63 content2 += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 64 content2 += " <Header/>\n"; 65 content2 += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 66 content2 += " <CMD_Component ComponentId=\"" + compDesc1.getId() + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 67 content2 += " </CMD_Component>\n"; 68 content2 += " </CMD_Component>\n"; 69 content2 += "</CMD_ComponentSpec>\n"; 70 ProfileDescription profileDesc = RegistryTestHelper.addProfile(testRegistry, "YYY1", content2); 71 71 72 AdminRegistry adminReg = new AdminRegistry(); 73 adminReg.setComponentRegistryFactory(componentRegistryFactory); 74 adminReg.setComponentDescriptionDao(componentDescriptionDao); 75 adminReg.setProfileDescriptionDao(profileDescriptionDao); 76 CMDItemInfo fileInfo = new CMDItemInfo(); 77 fileInfo.setForceUpdate(false); 78 fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, true)); 79 fileInfo.setContent(content1); 80 try { 81 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); 82 fail(); 83 } catch (SubmitFailedException e) {} 84 fileInfo.setForceUpdate(true); 85 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components 72 AdminRegistry adminReg = new AdminRegistry(); 73 adminReg.setComponentRegistryFactory(componentRegistryFactory); 74 adminReg.setComponentDescriptionDao(componentDescriptionDao); 75 adminReg.setProfileDescriptionDao(profileDescriptionDao); 76 CMDItemInfo fileInfo = new CMDItemInfo(); 77 fileInfo.setForceUpdate(false); 78 fileInfo.setDataNode(new DisplayDataNode(compDesc1.getName(), false, compDesc1, ComponentStatus.PUBLIC)); 79 fileInfo.setContent(content1); 80 try { 81 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); 82 fail(); 83 } catch (SubmitFailedException e) { 84 } 85 fileInfo.setForceUpdate(true); 86 adminReg.submitFile(fileInfo, PRINCIPAL_ADMIN); //Component needs to be forced because they can be used by other profiles/components 86 87 87 88 89 90 91 92 93 94 95 96 97 98 88 assertEquals(1, testRegistry.getComponentDescriptions().size()); 89 try { 90 fileInfo.setForceUpdate(false); 91 adminReg.delete(fileInfo, PRINCIPAL_ADMIN); 92 fail(); 93 } catch (SubmitFailedException e) { 94 assertTrue(e.getCause() instanceof DeleteFailedException); 95 } 96 assertEquals(1, testRegistry.getComponentDescriptions().size()); 97 fileInfo.setForceUpdate(true); 98 adminReg.delete(fileInfo, PRINCIPAL_ADMIN); 99 assertEquals(0, testRegistry.getComponentDescriptions().size()); 99 100 100 101 102 fileInfo.setDataNode(new DisplayDataNode(profileDesc.getName(), false, profileDesc, true));103 104 101 assertEquals(1, testRegistry.getProfileDescriptions().size()); 102 fileInfo.setForceUpdate(false); 103 fileInfo.setDataNode(new DisplayDataNode(profileDesc.getName(), false, profileDesc, ComponentStatus.PUBLIC)); 104 adminReg.delete(fileInfo, PRINCIPAL_ADMIN); //Profile do not need to be forced they cannot be used by other profiles 105 assertEquals(0, testRegistry.getProfileDescriptions().size()); 105 106 } 106 107 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImplTest.java
r1992 r1993 5 5 import clarin.cmdi.componentregistry.model.RegistryUser; 6 6 import clarin.cmdi.componentregistry.ComponentRegistry; 7 import clarin.cmdi.componentregistry.ComponentStatus; 8 import clarin.cmdi.componentregistry.OwnerUser; 7 9 import clarin.cmdi.componentregistry.UserCredentials; 10 import clarin.cmdi.componentregistry.UserUnauthorizedException; 8 11 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 9 12 import org.springframework.beans.factory.annotation.Autowired; … … 50 53 51 54 @Test 52 public void getComponentRegistry() {55 public void getComponentRegistry() throws UserUnauthorizedException { 53 56 // Get public 54 assertNotNull(componentRegistryFactory.getComponentRegistry( false, null));57 assertNotNull(componentRegistryFactory.getComponentRegistry(ComponentStatus.PUBLIC, null, null)); 55 58 56 59 // Get for non-existing user 57 60 final RegistryUser testUser = UserDaoTest.createTestUser(); 58 UserCredentials credentials = new DummyPrincipal(testUser. 59 getPrincipalName()).getCredentials(); 61 UserCredentials credentials = new DummyPrincipal(testUser.getPrincipalName()).getCredentials(); 60 62 61 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory. 62 getComponentRegistry(true, credentials); 63 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials); 63 64 assertNotNull(cr1); 64 65 // Get for existing user 65 ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory. 66 getComponentRegistry(true, credentials); 66 ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials);; 67 67 assertNotNull(cr2); 68 68 assertEquals(cr1.getOwner(), cr2.getOwner()); 69 69 70 70 // Get for another new user 71 UserCredentials credentials2 = new DummyPrincipal(testUser. 72 getPrincipalName() + "2").getCredentials(); 73 ComponentRegistryDbImpl cr3 = (ComponentRegistryDbImpl) componentRegistryFactory. 74 getComponentRegistry(true, credentials2); 71 UserCredentials credentials2 = new DummyPrincipal(testUser.getPrincipalName() + "2").getCredentials(); 72 ComponentRegistryDbImpl cr3 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, credentials2); 75 73 assertNotNull(cr3); 76 74 assertNotSame(cr1.getOwner(), cr3.getOwner()); … … 78 76 79 77 @Test 80 public void testGetOtherUserComponentRegistry() { 81 UserCredentials userCredentials = DummyPrincipal.DUMMY_PRINCIPAL. 82 getCredentials(); 78 public void testGetOtherUserComponentRegistry() throws UserUnauthorizedException { 79 UserCredentials userCredentials = DummyPrincipal.DUMMY_PRINCIPAL.getCredentials(); 83 80 84 81 // Create registry for new user 85 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory. 86 getComponentRegistry(true, userCredentials); 82 ComponentRegistryDbImpl cr1 = (ComponentRegistryDbImpl) componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, userCredentials); 87 83 88 String id = cr1.getOwner().getId().toString();84 Number id = cr1.getOwner().getId(); 89 85 90 86 // Get it as admin 91 ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory. 92 getOtherUserComponentRegistry(DummyPrincipal.DUMMY_ADMIN_PRINCIPAL, id); 87 ComponentRegistryDbImpl cr2 = (ComponentRegistryDbImpl) componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_ADMIN_PRINCIPAL, ComponentStatus.DEVELOPMENT, new OwnerUser(id)); 93 88 assertNotNull(cr2); 94 89 // Should be this user's registry … … 97 92 // Try get it as non-admin 98 93 try { 99 componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, id);94 componentRegistryFactory.getOtherUserComponentRegistry(DummyPrincipal.DUMMY_PRINCIPAL, ComponentStatus.DEVELOPMENT, new OwnerUser(id)); 100 95 fail("Non-admin can get other user's component registry"); 101 96 } catch (Exception ex) { -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r1916 r1993 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 4 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 5 import clarin.cmdi.componentregistry.ComponentStatus; 5 6 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 6 7 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryBeanFactory; … … 16 17 import com.sun.jersey.api.representation.Form; 17 18 import com.sun.jersey.multipart.FormDataMultiPart; 19 import java.awt.image.ComponentSampleModel; 18 20 import java.io.ByteArrayInputStream; 19 21 import java.util.Date; … … 689 691 @Test 690 692 public void testRegisterWithUserComponents() throws Exception { 691 ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry( true, DummyPrincipal.DUMMY_CREDENTIALS);693 ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, DummyPrincipal.DUMMY_CREDENTIALS); 692 694 String content = ""; 693 695 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/MDValidatorTest.java
r1816 r1993 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 4 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 5 import clarin.cmdi.componentregistry.ComponentStatus; 5 6 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase; 6 7 import clarin.cmdi.componentregistry.model.ComponentDescription; … … 164 165 String id1 = "component1"; 165 166 String id2 = "component2"; 166 ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry( true, DummyPrincipal.DUMMY_CREDENTIALS);167 ComponentRegistry userRegistry = componentRegistryFactory.getComponentRegistry(ComponentStatus.DEVELOPMENT, null, DummyPrincipal.DUMMY_CREDENTIALS); 167 168 168 169 String profileContent = "";
Note: See TracChangeset
for help on using the changeset viewer.