Changeset 5556
- Timestamp:
- 08/18/14 09:50:16 (10 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r5553 r5556 41 41 * @throws ComponentRegistryException 42 42 */ 43 List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException, UserUnauthorizedException ;43 List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException; 44 44 45 45 … … 52 52 * @throws ComponentRegistryException 53 53 */ 54 List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException ;54 List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException; 55 55 56 56 … … 60 60 * @throws ComponentRegistryException 61 61 */ 62 List<ProfileDescription> getProfileDescriptionsForMetadaEditor() throws ComponentRegistryException ;62 List<ProfileDescription> getProfileDescriptionsForMetadaEditor() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException; 63 63 64 64 /** … … 67 67 * @throws ComponentRegistryException 68 68 */ 69 List<ProfileDescription> getProfileDescriptionsForMetadaEditor(Number groupId) throws ComponentRegistryException, UserUnauthorizedException ;69 List<ProfileDescription> getProfileDescriptionsForMetadaEditor(Number groupId) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException; 70 70 71 71 ProfileDescription getProfileDescriptionAccessControlled(String id) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException; -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/AdminHomePage.java
r5549 r5556 29 29 import clarin.cmdi.componentregistry.ComponentRegistryException; 30 30 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 31 import clarin.cmdi.componentregistry.ItemNotFoundException; 31 32 import clarin.cmdi.componentregistry.MDMarshaller; 32 33 import clarin.cmdi.componentregistry.RegistrySpace; … … 53 54 private MDMarshaller marshaller; 54 55 55 public AdminHomePage(final PageParameters parameters) throws ComponentRegistryException {56 public AdminHomePage(final PageParameters parameters) throws ComponentRegistryException, ItemNotFoundException { 56 57 super(parameters); 57 58 adminRegistry.setComponentRegistryFactory(componentRegistryFactory); … … 181 182 } 182 183 183 private void reloadTreeModel(CMDItemInfo info) throws UserUnauthorizedException {184 private void reloadTreeModel(CMDItemInfo info) throws UserUnauthorizedException, ItemNotFoundException { 184 185 try { 185 186 tree.setModelObject(createDBTreeModel()); … … 254 255 } 255 256 256 private TreeModel createDBTreeModel() throws ComponentRegistryException, UserUnauthorizedException {257 private TreeModel createDBTreeModel() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 257 258 DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new DisplayDataNode("ComponentRegistry", false)); 258 259 DefaultMutableTreeNode publicNode = new DefaultMutableTreeNode(new DisplayDataNode("Public", false)); … … 270 271 } 271 272 272 private void add(DefaultMutableTreeNode parent, ComponentRegistry registry) throws ComponentRegistryException, UserUnauthorizedException {273 private void add(DefaultMutableTreeNode parent, ComponentRegistry registry) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 273 274 DefaultMutableTreeNode componentsNode = new DefaultMutableTreeNode(new DisplayDataNode("Components", false)); 274 275 parent.add(componentsNode); -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/StatisticsPage.java
r5549 r5556 14 14 import clarin.cmdi.componentregistry.ComponentRegistryException; 15 15 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 16 import clarin.cmdi.componentregistry.ItemNotFoundException; 16 17 import clarin.cmdi.componentregistry.RegistrySpace; 17 18 import clarin.cmdi.componentregistry.UserUnauthorizedException; … … 42 43 } 43 44 44 public StatisticsPage(final PageParameters pageParameters) throws IOException, ComponentRegistryException, UserUnauthorizedException {45 public StatisticsPage(final PageParameters pageParameters) throws IOException, ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 45 46 super(pageParameters); 46 47 ComponentRegistry registry = componentRegistryFactory.getComponentRegistry(RegistrySpace.PUBLISHED, null, null, null); … … 49 50 } 50 51 51 private void displayStatistics(ComponentRegistry registry) throws ComponentRegistryException, UserUnauthorizedException {52 private void displayStatistics(ComponentRegistry registry) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 52 53 List<ProfileDescription> profileList = registry.getProfileDescriptions(); 53 54 RepeatingView repeating = new RepeatingView("repeating"); -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r5553 r5556 155 155 } 156 156 } 157 158 @Override 159 public Number makeGroupMember(String principalName, String groupName) throws UserUnauthorizedException, ItemNotFoundException{157 158 @Override 159 public Number makeGroupMember(String principalName, String groupName) throws UserUnauthorizedException, ItemNotFoundException { 160 160 RegistryUser regOwner = userDao.getPrincipalNameById(registryOwner.getId()); 161 if (groupService.isUserOwnerOfGroup(groupName, regOwner.getPrincipalName()) ||162 configuration.isAdminUser(regOwner.getPrincipalName())) {163 return groupService.makeMember(principalName, groupName);161 if (groupService.isUserOwnerOfGroup(groupName, regOwner.getPrincipalName()) 162 || configuration.isAdminUser(regOwner.getPrincipalName())) { 163 return groupService.makeMember(principalName, groupName); 164 164 } else { 165 165 throw new UserUnauthorizedException("The registry owner is not the admin or not the owner of the group and cannot add users to the group"); 166 166 } 167 167 } 168 168 169 169 // @Override 170 170 // public long removeGroupMember(String principalName, String groupName) throws UserUnauthorizedException, ItemNotFoundException{ … … 177 177 // } 178 178 // } 179 180 181 @Override 182 public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException { 179 @Override 180 public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 183 181 try { 184 182 switch (registrySpace) { … … 234 232 235 233 @Override 236 public List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException, UserUnauthorizedException {234 public List<ComponentDescription> getComponentDescriptions() throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 237 235 try { 238 236 switch (registrySpace) { … … 861 859 862 860 private List<ComponentDescription> getComponentDescriptionsInGroup(Number groupId) 863 throws ComponentRegistryException, UserUnauthorizedException {861 throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 864 862 865 863 String principalName = userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName(); 866 867 if (!groupService.userGroupMember(principalName, groupId.toString())) { 864 String groupName = groupService.getGroupNameById(groupId.longValue()); 865 if (!groupService.userGroupMember(principalName, groupId.toString()) 866 && !groupService.isUserOwnerOfGroup(groupName, principalName)) { 868 867 throw new UserUnauthorizedException("The user \'" + principalName + "\' does not have access to components of the group " + groupId); 869 868 } … … 880 879 } 881 880 882 private List<ProfileDescription> getProfileDescriptionsInGroup(Number groupId) throws ComponentRegistryException, UserUnauthorizedException {881 private List<ProfileDescription> getProfileDescriptionsInGroup(Number groupId) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 883 882 884 883 String principalName = userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName(); 885 886 if (!groupService.userGroupMember(principalName, groupId.toString())) { 884 String groupName = groupService.getGroupNameById(groupId.longValue()); 885 if (!groupService.userGroupMember(principalName, groupId.toString()) 886 && !groupService.isUserOwnerOfGroup(groupName, principalName)) { 887 887 throw new UserUnauthorizedException("The user \'" + principalName + "\' does not have access to profiles of the group " + groupId); 888 888 } … … 900 900 901 901 @Override 902 public List<ProfileDescription> getProfileDescriptionsForMetadaEditor(Number groupId) throws UserUnauthorizedException, 903 ComponentRegistryException { 902 public List<ProfileDescription> getProfileDescriptionsForMetadaEditor(Number groupId) throws ComponentRegistryException, UserUnauthorizedException, ItemNotFoundException { 904 903 return this.getProfileDescriptionsInGroup(groupId.longValue()); 905 904 } … … 984 983 } 985 984 } 986 987 988 985 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r5553 r5556 200 200 return new ArrayList<ComponentDescription>(); 201 201 202 203 204 } catch (ItemNotFoundException e) { 205 response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString()); 206 return new ArrayList<ComponentDescription>(); 202 207 } 203 208 … … 235 240 } catch (UserUnauthorizedException e) { 236 241 response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString()); 242 return new ArrayList<ProfileDescription>(); 243 244 245 } catch (ItemNotFoundException e) { 246 response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString()); 237 247 return new ArrayList<ProfileDescription>(); 238 248 } … … 1558 1568 return new Rss(); 1559 1569 } 1570 catch (ItemNotFoundException e) { 1571 response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString()); 1572 return new Rss(); 1573 } 1560 1574 // obsolete, add group Id 1561 1575 final RssCreatorDescriptions instance = new RssCreatorDescriptions(!registrySpace.equalsIgnoreCase("published"), getApplicationBaseURI(), "components", … … 1596 1610 } catch (UserUnauthorizedException e) { 1597 1611 response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString()); 1612 return new Rss(); 1613 1614 } catch (ItemNotFoundException e) { 1615 response.sendError(Status.NOT_FOUND.getStatusCode(), e.toString()); 1598 1616 return new Rss(); 1599 1617 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java
r5553 r5556 49 49 return addComponent(testRegistry, id, getComponentTestContent(), isPublic); 50 50 } 51 51 52 52 53 public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content, boolean isPublic) throws ParseException, 53 54 JAXBException, UnsupportedEncodingException { … … 60 61 desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName()); 61 62 desc.setUserId(DummyPrincipal.DUMMY_PRINCIPAL.getName()); 63 desc.setName(id); 64 desc.setDescription("Test Description"); 65 desc.setId(ComponentDescription.COMPONENT_PREFIX + id); 66 desc.setHref("link:" + desc.getId()); 67 desc.setPublic(isPublic); 68 CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema()); 69 testRegistry.register(desc, spec); 70 return desc; 71 } 72 73 public static ComponentDescription addComponentAnotherPrincipal(ComponentRegistry testRegistry, String id, boolean isPublic) throws ParseException, JAXBException { 74 return addComponentAnotherPrincipal(testRegistry, id, getComponentTestContent(), isPublic); 75 } 76 77 private static ComponentDescription addComponentAnotherPrincipal(ComponentRegistry testRegistry, String id, InputStream content, boolean isPublic) throws ParseException, 78 JAXBException { 79 ComponentDescription desc = ComponentDescription.createNewDescription(); 80 desc.setCreatorName("AnotherPrincipal"); 81 desc.setUserId("AnotherPrincipal"); 82 desc.setDbUserId(2); 62 83 desc.setName(id); 63 84 desc.setDescription("Test Description"); … … 121 142 desc.setCreatorName(DummyPrincipal.DUMMY_CREDENTIALS.getDisplayName()); 122 143 desc.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName()); 144 desc.setName(id); 145 desc.setDescription("Test Description"); 146 desc.setId(ProfileDescription.PROFILE_PREFIX + id); 147 desc.setHref("link:" + ProfileDescription.PROFILE_PREFIX + id); 148 desc.setPublic(isPublic); 149 CMDComponentSpec spec = marshaller.unmarshal(CMDComponentSpec.class, content, marshaller.getCMDComponentSchema()); 150 testRegistry.register(desc, spec); 151 return desc; 152 } 153 154 public static ProfileDescription addProfileAnotherPrincipal(ComponentRegistry testRegistry, String id, boolean isPublic) throws ParseException, JAXBException, ItemNotFoundException { 155 return addProfileAnotherPrincipal(testRegistry, id, RegistryTestHelper.getTestProfileContent(), isPublic); 156 } 157 158 private static ProfileDescription addProfileAnotherPrincipal(ComponentRegistry testRegistry, String id, InputStream content, boolean isPublic) throws ParseException, 159 JAXBException, ItemNotFoundException { 160 ProfileDescription desc = ProfileDescription.createNewDescription(); 161 desc.setCreatorName("AnotherPrincipal"); 162 desc.setUserId("AnotherPrincipal"); 163 desc.setDbUserId(2); 123 164 desc.setName(id); 124 165 desc.setDescription("Test Description"); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RestGroupServiceTest.java
r5554 r5556 8 8 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 9 9 import clarin.cmdi.componentregistry.ItemNotFoundException; 10 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 10 11 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase; 11 12 import clarin.cmdi.componentregistry.impl.database.GroupService; … … 184 185 MakeGroupC(); 185 186 186 RegistryTestHelper.addProfile (baseRegistry, "Cprofile-1", false);187 RegistryTestHelper.addComponent (baseRegistry, "Ccomponent-1", false);188 RegistryTestHelper.addComponent (baseRegistry, "Ccomponent-2", false);187 RegistryTestHelper.addProfileAnotherPrincipal(baseRegistry, "Cprofile-1", false); 188 RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-1", false); 189 RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-2", false); 189 190 190 191 Ownership ownership = new Ownership(); … … 497 498 } 498 499 500 @Test 501 public void testGetGroupProfilesAndComponents() throws Exception { 502 503 System.out.println("test getGroupProfiles"); 504 505 fillUpGroupA(); 506 fillUpGroupB(); 507 fillUpGroupC(); 508 509 510 List<ProfileDescription> response = this.getAuthenticatedResource(getResource() 511 .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) 512 .get(PROFILE_LIST_GENERICTYPE); 513 assertEquals(1, response.size()); 514 515 List<ComponentDescription> responseC = this.getAuthenticatedResource(getResource() 516 .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) 517 .get(COMPONENT_LIST_GENERICTYPE); 518 assertEquals(2, responseC.size()); 519 520 response = this.getAuthenticatedResource(getResource() 521 .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) 522 .get(PROFILE_LIST_GENERICTYPE); 523 assertEquals(1, response.size()); 524 525 responseC = this.getAuthenticatedResource(getResource() 526 .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) 527 .get(COMPONENT_LIST_GENERICTYPE); 528 assertEquals(2, responseC.size()); 529 530 ClientResponse clientResponse = this.getAuthenticatedResource(getResource() 531 .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML) 532 .get(ClientResponse.class); 533 534 assertEquals(403, clientResponse.getStatus()); 535 536 537 CMDComponentSpec component = this.getAuthenticatedResource(getResource() 538 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1")) 539 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 540 assertNotNull(component); 541 assertEquals("Actor", component.getCMDComponent().getName()); 542 543 component = this.getAuthenticatedResource(getResource() 544 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1")) 545 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 546 assertNotNull(component); 547 assertEquals("Access", component.getCMDComponent().getName()); 548 549 component = this.getAuthenticatedResource(getResource() 550 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1")) 551 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 552 assertNotNull(component); 553 assertEquals("Actor", component.getCMDComponent().getName()); 554 555 component = this.getAuthenticatedResource(getResource() 556 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1")) 557 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 558 assertNotNull(component); 559 assertEquals("Access", component.getCMDComponent().getName()); 560 561 clientResponse = this.getAuthenticatedResource(getResource() 562 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1")) 563 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 564 assertEquals(403, clientResponse.getStatus()); 565 566 clientResponse = this.getAuthenticatedResource(getResource() 567 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1")) 568 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 569 assertEquals(403, clientResponse.getStatus()); 570 571 } 499 572 500 573 }
Note: See TracChangeset
for help on using the changeset viewer.