Changeset 1992
- Timestamp:
- 06/18/12 14:03:46 (12 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 6 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r1892 r1992 1 1 package clarin.cmdi.componentregistry; 2 3 import java.io.IOException;4 import java.io.OutputStream;5 import java.security.Principal;6 import java.util.List;7 2 8 3 import clarin.cmdi.componentregistry.components.CMDComponentSpec; … … 11 6 import clarin.cmdi.componentregistry.model.ComponentDescription; 12 7 import clarin.cmdi.componentregistry.model.ProfileDescription; 8 import java.io.IOException; 9 import java.io.OutputStream; 10 import java.security.Principal; 11 import java.util.List; 13 12 14 13 public interface ComponentRegistry { … … 18 17 19 18 /** 20 * 19 * 21 20 * @return List of component descriptions ordered by name ascending 22 21 * @throws ComponentRegistryException … … 27 26 28 27 /** 29 * 28 * 30 29 * @return List of profile descriptions ordered by name ascending 31 30 * @throws ComponentRegistryException … … 34 33 35 34 /** 36 * 35 * 37 36 * @return List of profile descriptions ordered by name ascending, only the ones marked for showing in metadata editor 38 37 * @throws ComponentRegistryException … … 47 46 48 47 /** 49 * 48 * 50 49 * @return -1 if profile could not be registered 51 50 */ … … 53 52 54 53 /** 55 * 54 * 56 55 * @param comment 57 56 * @return -1 if comment could not be registered … … 60 59 61 60 /** 62 * 61 * 63 62 * @return -1 if component could not be updated 64 63 */ … … 66 65 67 66 /** 68 * 67 * 69 68 * @return -1 if component could not be published. Published means move from 70 * 69 * current (private) workspace to public workspace. 71 70 */ 72 71 int publish(AbstractDescription desc, CMDComponentSpec spec, Principal principal); … … 81 80 82 81 /** 83 * 82 * 84 83 * @param profileId 85 84 * @param principal 86 85 * @throws IOException 87 86 * @throws UserUnauthorizedException 88 * 87 * thrown when principal does not match creator of profile 89 88 * @throws DeleteFailedException 90 89 */ … … 92 91 93 92 /** 94 * 93 * 95 94 * @param componentId 96 95 * @param principal 97 96 * @param forceDelete 98 * 99 * 97 * ignores the fact that the component is still in use by other 98 * components and just deletes. 100 99 * @throws IOException 101 100 * @throws UserUnauthorizedException 102 * 101 * thrown when principal does not match creator of component 103 102 * @throws DeleteFailedException 104 103 */ … … 107 106 108 107 /** 109 * 108 * 110 109 * @param componentId 111 110 * @return List of ComponentDescriptions of Components that use the given 112 * 111 * Component. 113 112 */ 114 113 List<ComponentDescription> getUsageInComponents(String componentId) throws ComponentRegistryException; 115 114 116 115 /** 117 * 116 * 118 117 * @param componentId 119 118 * @return List of ProfileDescriptions of Profiles that use the given 120 * 119 * Component. 121 120 */ 122 121 List<ProfileDescription> getUsageInProfiles(String componentId) throws ComponentRegistryException; … … 125 124 * Return true if this registry is the public registry as opposed to a 126 125 * registry used for the user privately. 127 * */126 * */ 128 127 boolean isPublic(); 129 128 129 ComponentStatus getStatus(); 130 131 Owner getOwner(); 132 130 133 /** 131 134 * @return {@link ComponentRegistry.PUBLIC_NAME} or name of the user's workspace … … 134 137 135 138 /** 136 * 139 * 137 140 * @return List of profile descriptions ordered by name ascending 138 141 */ … … 140 143 141 144 /** 142 * 145 * 143 146 * @return List of component descriptions ordered by name ascending 144 147 */ … … 146 149 147 150 /** 148 * 151 * 149 152 * @param profileId 150 153 * @return List of comments fro a specific profile 151 * @throws ComponentRegistryException 154 * @throws ComponentRegistryException 152 155 */ 153 156 List<Comment> getCommentsInProfile(String profileId, Principal principal) throws ComponentRegistryException; 154 157 155 158 /** 156 * 159 * 157 160 * @param profileId Id of profile to retrieve comment from 158 161 * @param commentId Id of comment to retrieve 159 162 * @return a specific comment from a profile 160 * @throws ComponentRegistryException 163 * @throws ComponentRegistryException 161 164 */ 162 165 Comment getSpecifiedCommentInProfile(String profileId, String commentId, Principal principal) throws ComponentRegistryException; 163 166 164 167 /** 165 * 168 * 166 169 * @param componentId 167 170 * @return List of comments from a specific component 168 * @throws ComponentRegistryException 171 * @throws ComponentRegistryException 169 172 */ 170 173 List<Comment> getCommentsInComponent(String componentId, Principal principal) throws ComponentRegistryException; 171 174 172 175 /** 173 * 176 * 174 177 * @param componentId Id of component to retrieve comment from 175 178 * @param commentId Id of comment to retrieve 176 179 * @return a specific comment from a component 177 * @throws ComponentRegistryException 180 * @throws ComponentRegistryException 178 181 */ 179 182 Comment getSpecifiedCommentInComponent(String componentId, String commentId, Principal principal) throws ComponentRegistryException; 180 183 181 184 /** 182 * 185 * 183 186 * @param commentId Id of comment to delete 184 187 * @param principal User principal … … 186 189 * @throws ComponentRegistryException When comment cannot be successfully retrieved from registry 187 190 * @throws UserUnauthorizedException 188 * @throws DeleteFailedException 191 * @throws DeleteFailedException 189 192 */ 190 193 public void deleteComment(String commentId, Principal principal) throws IOException, ComponentRegistryException, UserUnauthorizedException, … … 192 195 193 196 /** 194 * 197 * 195 198 * @return a component specification expander for this registry 196 199 */ -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1895 r1992 2 2 3 3 import clarin.cmdi.componentregistry.CMDComponentSpecExpander; 4 import clarin.cmdi.componentregistry.ComponentRegistry; 5 import clarin.cmdi.componentregistry.ComponentRegistryException; 6 import clarin.cmdi.componentregistry.ComponentStatus; 7 import clarin.cmdi.componentregistry.Configuration; 8 import clarin.cmdi.componentregistry.DeleteFailedException; 9 import clarin.cmdi.componentregistry.MDMarshaller; 10 import clarin.cmdi.componentregistry.Owner; 11 import clarin.cmdi.componentregistry.OwnerGroup; 12 import clarin.cmdi.componentregistry.OwnerUser; 13 import clarin.cmdi.componentregistry.UserUnauthorizedException; 14 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 15 import clarin.cmdi.componentregistry.impl.ComponentRegistryImplBase; 16 import clarin.cmdi.componentregistry.model.AbstractDescription; 17 import clarin.cmdi.componentregistry.model.Comment; 18 import clarin.cmdi.componentregistry.model.ComponentDescription; 19 import clarin.cmdi.componentregistry.model.ProfileDescription; 20 import clarin.cmdi.componentregistry.model.RegistryUser; 4 21 import java.io.ByteArrayInputStream; 5 22 import java.io.ByteArrayOutputStream; … … 11 28 import java.text.ParseException; 12 29 import java.util.Calendar; 30 import java.util.Collection; 31 import java.util.Collections; 13 32 import java.util.Date; 14 33 import java.util.List; 15 16 34 import javax.xml.bind.JAXBException; 17 18 35 import org.slf4j.Logger; 19 36 import org.slf4j.LoggerFactory; … … 21 38 import org.springframework.beans.factory.annotation.Qualifier; 22 39 import org.springframework.dao.DataAccessException; 23 24 import clarin.cmdi.componentregistry.ComponentRegistry;25 import clarin.cmdi.componentregistry.ComponentRegistryException;26 import clarin.cmdi.componentregistry.Configuration;27 import clarin.cmdi.componentregistry.DeleteFailedException;28 import clarin.cmdi.componentregistry.MDMarshaller;29 import clarin.cmdi.componentregistry.UserUnauthorizedException;30 import clarin.cmdi.componentregistry.components.CMDComponentSpec;31 import clarin.cmdi.componentregistry.impl.ComponentRegistryImplBase;32 import clarin.cmdi.componentregistry.model.AbstractDescription;33 import clarin.cmdi.componentregistry.model.Comment;34 import clarin.cmdi.componentregistry.model.ComponentDescription;35 import clarin.cmdi.componentregistry.model.ProfileDescription;36 import clarin.cmdi.componentregistry.model.RegistryUser;37 import java.util.Collection;38 import java.util.Collections;39 40 40 41 /** … … 47 48 48 49 private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryDbImpl.class); 49 private Number userId; 50 private Owner owner; 51 private ComponentStatus status; 50 52 @Autowired 51 53 private Configuration configuration; 54 @Autowired 55 @Qualifier("componentsCache") 56 private CMDComponentSpecCache componentsCache; 57 @Autowired 58 @Qualifier("profilesCache") 59 private CMDComponentSpecCache profilesCache; 60 // DAO's 52 61 @Autowired 53 62 private ProfileDescriptionDao profileDescriptionDao; … … 57 66 private UserDao userDao; 58 67 @Autowired 59 @Qualifier("componentsCache")60 private CMDComponentSpecCache componentsCache;61 @Autowired62 @Qualifier("profilesCache")63 private CMDComponentSpecCache profilesCache;64 @Autowired65 68 private CommentsDao commentsDao; 66 69 67 70 /** 68 * Default constructor, makes this a (spring) bean. No user is set, so69 * public registry by default. Use setUser() to make it a userregistry.71 * Default constructor, to use this as a (spring) bean. The public registry by default. 72 * Use setStatus() and setOwner() to make it another kind of registry. 70 73 * 71 74 * @see setUser 72 75 */ 73 76 public ComponentRegistryDbImpl() { 77 this.status = ComponentStatus.PUBLIC; 74 78 } 75 79 76 80 /** 77 81 * Creates a new ComponentRegistry (either public or not) for the provided 78 * user 82 * user. Only use for test and/or make sure to inject all dao's and other services 79 83 * 80 84 * @param userId … … 82 86 * public 83 87 */ 84 public ComponentRegistryDbImpl(Number userId) { 85 this.userId = userId; 88 public ComponentRegistryDbImpl(ComponentStatus status, Owner owner) { 89 this.status = status; 90 this.owner = owner; 86 91 } 87 92 … … 89 94 public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException { 90 95 try { 91 if (isPublic()) { 92 return profileDescriptionDao.getPublicProfileDescriptions(); 93 } else { 94 return profileDescriptionDao.getUserspaceDescriptions(getUserId()); 96 switch (status) { 97 // TODO: support other status types 98 case DEVELOPMENT: 99 if (owner == null) { 100 throw new ComponentRegistryException("Development workspace without owner!"); 101 } 102 // TODO: Support group space 103 return profileDescriptionDao.getUserspaceDescriptions(owner.getId()); 104 case PUBLIC: 105 return profileDescriptionDao.getPublicProfileDescriptions(); 106 default: 107 throw new ComponentRegistryException("Unsupported status type" + status); 95 108 } 96 109 } catch (DataAccessException ex) { … … 331 344 } 332 345 } else { 333 uid = userId;346 uid = getUserId(); // this can be null as well 334 347 } 335 348 if (uid != null) { … … 491 504 } 492 505 493 @Override 506 /** 507 * 508 * @return whether this is the public registry 509 * @deprecated use {@link #getStatus() } to check if this is the {@link ComponentStatus#PUBLIC public registry} 510 */ 511 @Override 512 @Deprecated 494 513 public boolean isPublic() { 495 return null == userId; 496 } 497 498 public void setPublic() { 499 this.userId = null; 500 } 501 502 /** 503 * @return The user, or null if this is the public registry. 504 */ 505 public Number getUserId() { 506 return userId; 507 } 508 509 /** 510 * @param User 511 * for which this should be the registry. Pass null for the 512 * public registry 513 */ 514 public void setUserId(Number user) { 515 this.userId = user; 514 return status == ComponentStatus.PUBLIC; 515 } 516 517 /** 518 * @return The user id, or null if there is no owner or it is not a user. 519 */ 520 private Number getUserId() { 521 if (owner instanceof OwnerUser) { 522 return owner.getId(); 523 } else { 524 return null; 525 } 526 } 527 528 /** 529 * @return The group id, or null if there is no owner or it is not a group. 530 */ 531 private Number getGroupId() { 532 if (owner instanceof OwnerGroup) { 533 return owner.getId(); 534 } else { 535 return null; 536 } 537 } 538 539 @Override 540 public Owner getOwner() { 541 return owner; 542 } 543 544 /** 545 * Sets status and owner of this registry 546 * 547 * @param status new status for registry 548 * @param owner new owner for registry 549 */ 550 public void setStatus(ComponentStatus status, Owner owner) { 551 setStatus(status); 552 this.owner = owner; 553 } 554 555 public void setStatus(ComponentStatus status) { 556 this.status = status; 557 } 558 559 @Override 560 public ComponentStatus getStatus() { 561 return status; 516 562 } 517 563 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImpl.java
r1863 r1992 12 12 import clarin.cmdi.componentregistry.ComponentRegistry; 13 13 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 14 import clarin.cmdi.componentregistry.ComponentStatus; 14 15 import clarin.cmdi.componentregistry.Configuration; 16 import clarin.cmdi.componentregistry.OwnerUser; 15 17 import clarin.cmdi.componentregistry.UserCredentials; 16 18 import clarin.cmdi.componentregistry.model.RegistryUser; … … 101 103 private ComponentRegistry getNewComponentRegistryForUser(Number userId) { 102 104 ComponentRegistryDbImpl componentRegistry = componentRegistryBeanFactory.getNewComponentRegistry(); 103 componentRegistry.setUserId(userId); 105 if (userId != null) { 106 // Null means public registry 107 // TODO: Make this more explicit 108 componentRegistry.setStatus(ComponentStatus.DEVELOPMENT, new OwnerUser(userId)); 109 } 104 110 return componentRegistry; 105 111 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java
r1892 r1992 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 4 import clarin.cmdi.componentregistry.ComponentRegistryException; 5 import clarin.cmdi.componentregistry.ComponentStatus; 5 6 import clarin.cmdi.componentregistry.DeleteFailedException; 7 import clarin.cmdi.componentregistry.OwnerGroup; 8 import clarin.cmdi.componentregistry.OwnerUser; 6 9 import clarin.cmdi.componentregistry.UserCredentials; 7 10 import clarin.cmdi.componentregistry.UserUnauthorizedException; … … 374 377 private ComponentRegistry getComponentRegistryForUser(Number userId) { 375 378 ComponentRegistryDbImpl componentRegistry = componentRegistryBeanFactory.getNewComponentRegistry(); 376 componentRegistry.setUserId(userId); 379 if (userId != null) { 380 componentRegistry.setStatus(ComponentStatus.DEVELOPMENT, new OwnerUser(userId)); 381 } 377 382 return componentRegistry; 378 383 } … … 669 674 assertEquals("0", comment.getUserId()); 670 675 assertEquals(USER_CREDS.getDisplayName(), comment.getUserName()); 671 676 672 677 // Should not be allowed to delete, not authenticated 673 678 assertFalse(comment.isCanDelete()); … … 774 779 assertEquals("Registry of J.Unit", register.getName()); 775 780 } 781 782 @Test 783 public void testGetStatus() { 784 ComponentRegistry register = new ComponentRegistryDbImpl(); 785 assertEquals(ComponentStatus.PUBLIC, register.getStatus()); 786 register = new ComponentRegistryDbImpl(ComponentStatus.DEVELOPMENT, null); 787 assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus()); 788 } 789 790 @Test 791 public void testGetOwner() { 792 ComponentRegistry register = new ComponentRegistryDbImpl(); 793 assertNull(register.getOwner()); 794 register = new ComponentRegistryDbImpl(ComponentStatus.DEVELOPMENT, new OwnerUser(101)); 795 assertEquals(new OwnerUser(101), register.getOwner()); 796 797 register = new ComponentRegistryDbImpl(ComponentStatus.DEVELOPMENT, new OwnerGroup(101)); 798 assertEquals(new OwnerGroup(101), register.getOwner()); 799 } 800 801 @Test 802 public void testSetStatus() throws Exception { 803 // Construct with an owner 804 ComponentRegistryDbImpl register = new ComponentRegistryDbImpl(ComponentStatus.PUBLIC, new OwnerUser(101)); 805 register.setStatus(ComponentStatus.DEVELOPMENT); 806 assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus()); 807 // Owner should remain unchanged 808 assertEquals(new OwnerUser(101), register.getOwner()); 809 810 // Construct with no owner 811 register = new ComponentRegistryDbImpl(ComponentStatus.PUBLIC, null); 812 register.setStatus(ComponentStatus.DEVELOPMENT); 813 assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus()); 814 // Owner should remain unchanged 815 assertNull(register.getOwner()); 816 } 817 818 @Test 819 public void testSetStatusAndOwner() throws Exception { 820 ComponentRegistryDbImpl register = new ComponentRegistryDbImpl(ComponentStatus.PUBLIC, new OwnerUser(101)); 821 822 register.setStatus(ComponentStatus.DEVELOPMENT, new OwnerGroup(102)); 823 assertEquals(ComponentStatus.DEVELOPMENT, register.getStatus()); 824 assertEquals(new OwnerGroup(102), register.getOwner()); 825 } 776 826 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImplTest.java
r1696 r1992 66 66 getComponentRegistry(true, credentials); 67 67 assertNotNull(cr2); 68 assertEquals(cr1.get UserId(), cr2.getUserId());68 assertEquals(cr1.getOwner(), cr2.getOwner()); 69 69 70 70 // Get for another new user … … 74 74 getComponentRegistry(true, credentials2); 75 75 assertNotNull(cr3); 76 assertNotSame(cr1.get UserId(), cr3.getUserId());76 assertNotSame(cr1.getOwner(), cr3.getOwner()); 77 77 } 78 78 … … 86 86 getComponentRegistry(true, userCredentials); 87 87 88 String id = cr1.get UserId().toString();88 String id = cr1.getOwner().getId().toString(); 89 89 90 90 // Get it as admin … … 93 93 assertNotNull(cr2); 94 94 // Should be this user's registry 95 assertEquals(cr1.get UserId(), cr2.getUserId());95 assertEquals(cr1.getOwner(), cr2.getOwner()); 96 96 97 97 // Try get it as non-admin
Note: See TracChangeset
for help on using the changeset viewer.