Changeset 836
- Timestamp:
- 11/03/10 10:25:21 (14 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry
- Files:
-
- 4 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/pom.xml
r669 r836 38 38 <artifactId>jaxb-impl</artifactId> 39 39 <version>2.1</version> 40 </dependency>41 40 <scope>provided</scope> 41 </dependency> 42 42 <dependency> 43 43 <groupId>javax.servlet</groupId> … … 156 156 <serviceRootUrl>http://localhost:8080/${pom.artifactId}</serviceRootUrl> 157 157 <isocatSearchUrl>http://www.isocat.org/rest/user/guest/search</isocatSearchUrl> 158 <registryRoot>/tmp/ComponentRegistry</registryRoot> <!-- /Users/patdui/Workspace/Clarin/MyRegistry -->158 <registryRoot>/tmp/ComponentRegistry</registryRoot> 159 159 <ComponentBrowserGuiVersion>1.6-SNAPSHOT</ComponentBrowserGuiVersion> 160 160 <ComponentRegistrySwfName>${pom.artifactId}-${ComponentBrowserGuiVersion}</ComponentRegistrySwfName> -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/AdminRegistry.java
r663 r836 27 27 try { 28 28 File file = fileInfo.getFileNode().getFile(); 29 if ( 29 if (fileInfo.getFileNode().isDeleted()) { 30 30 //already deleted file 31 31 FileUtils.writeStringToFile(file, fileInfo.getText(), "UTF-8"); … … 121 121 122 122 private int submitToRegistry(AbstractDescription description, CMDComponentSpec spec, Principal userPrincipal, FileInfo fileInfo) { 123 ComponentRegistry registry = getRegistry(userPrincipal, description, fileInfo); 123 ComponentRegistry registry = getRegistry(userPrincipal, description, fileInfo); 124 124 if (spec.isIsProfile()) { 125 return registry.register MDProfile((ProfileDescription) description, spec);125 return registry.register((ProfileDescription) description, spec); 126 126 } else { 127 return registry.register MDComponent((ComponentDescription) description, spec);127 return registry.register((ComponentDescription) description, spec); 128 128 } 129 129 130 130 } 131 131 132 private void deleteFromRegistry(Principal userPrincipal, AbstractDescription desc, FileInfo fileInfo) throws IOException, UserUnauthorizedException,133 DeleteFailedException {134 ComponentRegistry registry = getRegistry(userPrincipal, desc, fileInfo); 132 private void deleteFromRegistry(Principal userPrincipal, AbstractDescription desc, FileInfo fileInfo) throws IOException, 133 UserUnauthorizedException, DeleteFailedException { 134 ComponentRegistry registry = getRegistry(userPrincipal, desc, fileInfo); 135 135 LOG.info("Deleting item: " + desc); 136 136 if (desc.isProfile()) { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r663 r836 5 5 import java.security.Principal; 6 6 import java.util.List; 7 8 import javax.xml.bind.JAXBException;9 7 10 8 import clarin.cmdi.componentregistry.components.CMDComponentSpec; … … 33 31 * @return -1 if profile could not be registered 34 32 */ 35 int register MDProfile(ProfileDescription description, CMDComponentSpec spec);33 int register(AbstractDescription desc, CMDComponentSpec spec); 36 34 37 int registerMDComponent(ComponentDescription description, CMDComponentSpec spec); 35 /** 36 * 37 * @return -1 if component could not be updated 38 */ 39 int update(AbstractDescription description, CMDComponentSpec spec); 38 40 39 41 void getMDProfileAsXml(String profileId, OutputStream output); … … 64 66 * @throws DeleteFailedException 65 67 */ 66 void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, DeleteFailedException; 67 68 void update(AbstractDescription desc, Principal principal, CMDComponentSpec spec) throws IOException, JAXBException, 69 UserUnauthorizedException; 68 void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException, 69 DeleteFailedException; 70 70 71 71 /** -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryImpl.java
r663 r836 21 21 import javax.xml.bind.JAXBException; 22 22 23 import org.apache.commons.collections.Closure; 23 24 import org.apache.commons.collections.map.LRUMap; 24 25 import org.apache.commons.io.FileUtils; … … 29 30 import org.apache.commons.io.filefilter.WildcardFileFilter; 30 31 import org.apache.commons.lang.StringUtils; 31 import org.apache.commons.lang.time.DateFormatUtils;32 import org.apache.commons.lang.time.DateUtils;33 32 import org.slf4j.Logger; 34 33 import org.slf4j.LoggerFactory; … … 217 216 public File getProfileFile(String profileId) { 218 217 String id = stripRegistryId(profileId); 219 File file = new File( resourceConfig.getProfileDir(), id + File.separator + id + ".xml");218 File file = new File(getProfileDir(), id + File.separator + id + ".xml"); 220 219 return file; 221 220 } … … 252 251 public File getComponentFile(String componentId) { 253 252 String id = stripRegistryId(componentId); 254 File file = new File( resourceConfig.getComponentDir(), id + File.separator + id + ".xml");253 File file = new File(getComponentDir(), id + File.separator + id + ".xml"); 255 254 return file; 256 255 } … … 273 272 * CMDComponentSpec and description are assumed to be valid. 274 273 */ 275 public int registerMDComponent(ComponentDescription description, CMDComponentSpec spec) { 276 LOG.info("Attempt to register component: " + description); 277 return register(resourceConfig.getComponentDir(), description, spec, "component"); 278 } 279 280 /** 281 * CMDComponentSpec and description are assumed to be valid. 282 */ 283 public int registerMDProfile(ProfileDescription profileDescription, CMDComponentSpec spec) { 284 LOG.info("Attempt to register profile: " + profileDescription); 285 return register(resourceConfig.getProfileDir(), profileDescription, spec, "profile"); 286 } 287 288 private int register(File storageDir, AbstractDescription description, CMDComponentSpec spec, String type) { 274 public int register(AbstractDescription desc, CMDComponentSpec spec) { 275 LOG.info("Attempt to register " + desc.getType() + ": " + desc); 276 return register(getDir(desc), desc, spec, new RegisterClosureOnFail(desc)); 277 } 278 279 public int update(AbstractDescription desc, CMDComponentSpec spec) { 280 LOG.info("Attempt to update " + desc.getType() + ": " + desc); 281 return register(getDir(desc), desc, spec, new UpdateClosureOnFail(desc)); 282 } 283 284 private File getDir(AbstractDescription desc) { 285 return desc.isProfile() ? getProfileDir() : getComponentDir(); 286 } 287 288 private int register(File storageDir, AbstractDescription description, CMDComponentSpec spec, Closure onFail) { 289 289 String strippedId = stripRegistryId(description.getId()); 290 290 File dir = new File(storageDir, strippedId); … … 292 292 try { 293 293 boolean dirCreated = dir.mkdir(); 294 if (dirCreated ) {294 if (dirCreated || dir.exists()) { 295 295 writeDescription(dir, description); 296 enrichSpecHeader(spec, description); 297 writeCMDComponentSpec(dir, strippedId + ".xml", spec); 296 if (spec != null) { 297 enrichSpecHeader(spec, description); 298 writeCMDComponentSpec(dir, strippedId + ".xml", spec); 299 } 298 300 success = true; 299 301 } … … 304 306 } finally { 305 307 if (!success) { 306 LOG.info("Registration of " + type + " " + description + " unsuccessful. Cleaning up created folders."); 307 try { 308 FileUtils.deleteDirectory(dir); 309 } catch (IOException e) { 310 LOG.error("Error in registration. Cleaning up " + type + " failed: " + dir + " :", e); 311 } 308 onFail.execute(dir); 312 309 return -1; 313 310 } 314 311 } 315 LOG.info("Succesfully registered a " + type + " in " + dir + " " + type + "= " + description); 312 LOG.info("Succesfully registered/updated a " + description.getType() + " in " + dir + " " + description.getType() + "= " 313 + description); 316 314 updateCache(description); 317 315 return 0; … … 327 325 header.setDescription(description.getDescription()); 328 326 } 329 330 327 } 331 328 … … 359 356 360 357 private void checkAuthorisation(AbstractDescription desc, Principal principal) throws UserUnauthorizedException { 361 if (!desc.isThisTheOwner(principal.getName()) && !Configuration.getInstance().isAdminUser(principal)) { 358 if (!desc.isThisTheOwner(principal.getName()) && !Configuration.getInstance().isAdminUser(principal)) { 362 359 throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName() 363 360 + "' is not the creator (nor an administrator) of the " + (desc.isProfile() ? "profile" : "component") + "(" + desc … … 366 363 } 367 364 368 public void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, UserUnauthorizedException,369 DeleteFailedException {365 public void deleteMDComponent(String componentId, Principal principal, boolean forceDelete) throws IOException, 366 UserUnauthorizedException, DeleteFailedException { 370 367 ComponentDescription desc = componentDescriptions.get(componentId); 371 368 if (desc != null) { … … 386 383 if (isPublic() && !Configuration.getInstance().isAdminUser(principal)) { 387 384 try { 388 Date regDate = DateUtils.parseDate(desc.getRegistrationDate(), new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT 389 .getPattern() }); 385 Date regDate = AbstractDescription.getDate(desc.getRegistrationDate()); 390 386 Calendar calendar = Calendar.getInstance(); 391 387 calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); … … 428 424 } 429 425 430 431 /**432 * spec is optional can be null if only the description needs to be updated.433 */434 public void update(AbstractDescription description, Principal principal, CMDComponentSpec spec) throws IOException, JAXBException,435 UserUnauthorizedException {436 if (!Configuration.getInstance().isAdminUser(principal)) {437 throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName()438 + "' cannot update this description (" + description + ").");439 }440 File typeDir;441 if (description.isProfile()) {442 typeDir = getProfileDir();443 } else {444 typeDir = getComponentDir();445 }446 String strippedId = stripRegistryId(description.getId());447 File dir = new File(typeDir, strippedId);448 writeDescription(dir, description);449 if (spec != null)450 writeCMDComponentSpec(dir, strippedId + ".xml", spec);451 updateCache(description);452 }453 454 426 public List<ComponentDescription> getUsageInComponents(String componentId) { 455 427 List<ComponentDescription> result = new ArrayList<ComponentDescription>(); … … 504 476 } 505 477 478 private class RegisterClosureOnFail implements Closure { 479 480 private final AbstractDescription desc; 481 482 RegisterClosureOnFail(AbstractDescription desc) { 483 this.desc = desc; 484 } 485 486 @Override 487 public void execute(Object input) { 488 File dir = (File) input; 489 LOG.info("Registration of " + desc + " unsuccessful. Cleaning up created folders."); 490 try { 491 FileUtils.deleteDirectory(dir); 492 } catch (IOException e) { 493 LOG.error("Error in registration. Cleaning up " + desc.getId() + " failed: " + dir + " :", e); 494 } 495 496 } 497 } 498 499 private class UpdateClosureOnFail implements Closure { 500 501 private final AbstractDescription desc; 502 503 UpdateClosureOnFail(AbstractDescription desc) { 504 this.desc = desc; 505 } 506 507 @Override 508 public void execute(Object input) { 509 LOG.info("Update of " + desc + " unsuccessful."); 510 } 511 512 } 506 513 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/MassMigratePage.java
r622 r836 113 113 desc.setUserId(userId); 114 114 try { 115 registry.update(desc, getUserPrincipal(),null);115 registry.update(desc, null); 116 116 info("Updated: " + desc); 117 117 } catch (Exception e) { … … 131 131 desc.setDescription(specDescription); 132 132 try { 133 registry.update(desc, getUserPrincipal(),null);133 registry.update(desc, null); 134 134 info("Updated: " + desc); 135 135 } catch (Exception e) { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/AbstractDescription.java
r622 r836 1 1 package clarin.cmdi.componentregistry.model; 2 2 3 import java.text.ParseException; 3 4 import java.util.Date; 4 5 … … 10 11 import org.apache.commons.codec.digest.DigestUtils; 11 12 import org.apache.commons.lang.time.DateFormatUtils; 13 import org.apache.commons.lang.time.DateUtils; 12 14 13 15 @XmlAccessorType(XmlAccessType.FIELD) … … 102 104 } 103 105 106 public String getType() { 107 return isProfile() ? "profile" : "component"; 108 } 109 104 110 public static String createNewDate() { 105 111 return DateFormatUtils.formatUTC(new Date(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); … … 115 121 } 116 122 123 public static Date getDate(String registrationDate) throws ParseException { 124 return DateUtils.parseDate(registrationDate, new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() }); 125 } 126 117 127 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r665 r836 181 181 } 182 182 183 @POST 184 @Path("/profiles/{profileId}/update") 185 @Consumes("multipart/form-data") 186 public Response updateRegisteredProfile(@PathParam("profileId") String profileId, 187 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input, 188 @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description, 189 @FormDataParam(DOMAIN_FORM_FIELD) String domainName) { 190 Principal principal = checkAndGetUserPrincipal(); 191 UserCredentials userCredentials = getUserCredentials(principal); 192 ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId); 193 if (desc != null) { 194 desc.setName(name); 195 desc.setDescription(description); 196 desc.setDomainName(domainName); 197 desc.setRegistrationDate(AbstractDescription.createNewDate()); 198 return register(input, desc, userCredentials, userspace, true); 199 } else { 200 LOG.error("Update of nonexistent id (" + profileId + ") failed."); 201 return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build(); 202 } 203 } 204 183 205 /** 184 206 * … … 197 219 } else { 198 220 return Response.ok().build(); 221 } 222 } 223 224 @POST 225 @Path("/components/{componentId}/update") 226 @Consumes("multipart/form-data") 227 public Response updateRegisteredComponent(@PathParam("componentId") String componentId, 228 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input, 229 @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description, 230 @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) { 231 Principal principal = checkAndGetUserPrincipal(); 232 UserCredentials userCredentials = getUserCredentials(principal); 233 ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId); 234 if (desc != null) { 235 desc.setName(name); 236 desc.setDescription(description); 237 desc.setGroupName(group); 238 desc.setDomainName(domainName); 239 desc.setRegistrationDate(AbstractDescription.createNewDate()); 240 return register(input, desc, userCredentials, userspace, true); 241 } else { 242 LOG.error("Update of nonexistent id (" + componentId + ") failed."); 243 return Response.serverError().entity("Invalid id, cannot update nonexistent component").build(); 199 244 } 200 245 } … … 291 336 @Produces( { MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) 292 337 @Consumes("multipart/form-data") 293 public Re gisterResponse registerProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,338 public Response registerProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name, 294 339 @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(DOMAIN_FORM_FIELD) String domainName, 295 340 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) { … … 303 348 desc.setDomainName(domainName); 304 349 LOG.info("Trying to register Profile: " + desc); 305 return register(input, desc, userCredentials, userspace );350 return register(input, desc, userCredentials, userspace, false); 306 351 } 307 352 … … 310 355 @Produces( { MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) 311 356 @Consumes("multipart/form-data") 312 public RegisterResponse registerComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input, 313 @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description, 314 @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName, 315 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) { 357 public Response registerComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name, 358 @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group, 359 @FormDataParam(DOMAIN_FORM_FIELD) String domainName, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) { 316 360 Principal principal = checkAndGetUserPrincipal(); 317 361 UserCredentials userCredentials = getUserCredentials(principal); … … 324 368 desc.setDomainName(domainName); 325 369 LOG.info("Trying to register Component: " + desc); 326 return register(input, desc, userCredentials, userspace );370 return register(input, desc, userCredentials, userspace, false); 327 371 } 328 372 … … 342 386 } 343 387 344 private RegisterResponse register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace) { 388 private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace, 389 boolean update) { 345 390 try { 346 391 ComponentRegistry registry = getRegistry(userspace, userCredentials); … … 352 397 if (response.getErrors().isEmpty()) { 353 398 CMDComponentSpec spec = validator.getCMDComponentSpec(); 354 int returnCode = spec.isIsProfile() ? registry.registerMDProfile((ProfileDescription) desc, spec) : registry 355 .registerMDComponent((ComponentDescription) desc, spec); 399 int returnCode; 400 if (update) { 401 returnCode = registry.update(desc, spec); 402 } else { 403 returnCode = registry.register(desc, spec); 404 } 356 405 if (returnCode == 0) { 357 406 response.setRegistered(true); … … 366 415 } 367 416 response.setIsProfile(desc.isProfile()); 368 return response;417 return Response.ok(response).build(); 369 418 } finally { 370 419 try { -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/ComponentRegistryImplTest.java
r671 r836 31 31 32 32 @Test 33 public void testRegister MDProfile() throws JAXBException {33 public void testRegisterProfile() throws JAXBException { 34 34 ComponentRegistry register = getTestRegistry(getRegistryDir()); 35 35 ProfileDescription description = ProfileDescription.createNewDescription(); … … 45 45 assertNull(testProfile.getHeader().getDescription()); 46 46 47 register.register MDProfile(description, testProfile);47 register.register(description, testProfile); 48 48 49 49 assertEquals(0, register.getComponentDescriptions().size()); … … 60 60 61 61 @Test 62 public void testRegister MDComponent() throws JAXBException {62 public void testRegisterComponent() throws JAXBException { 63 63 ComponentRegistry register = getTestRegistry(getRegistryDir()); 64 64 ComponentDescription description = ComponentDescription.createNewDescription(); … … 75 75 testComponent.getHeader().setDescription("Will not be overwritten"); 76 76 77 register.register MDComponent(description, testComponent);77 register.register(description, testComponent); 78 78 79 79 assertEquals(1, register.getComponentDescriptions().size()); … … 102 102 assertEquals(0, register.getComponentDescriptions().size()); 103 103 assertEquals(0, register.getProfileDescriptions().size()); 104 register.register MDProfile(description, RegistryTestHelper.getTestProfile());104 register.register(description, RegistryTestHelper.getTestProfile()); 105 105 assertEquals(0, register.getComponentDescriptions().size()); 106 106 assertEquals(1, register.getProfileDescriptions().size()); … … 131 131 assertEquals(0, publicReg.getComponentDescriptions().size()); 132 132 assertEquals(0, publicReg.getProfileDescriptions().size()); 133 userReg.register MDComponent(cDesc, RegistryTestHelper.getTestComponent());134 publicReg.register MDComponent(cDesc, RegistryTestHelper.getTestComponent());135 publicReg.register MDProfile(pDesc, RegistryTestHelper.getTestProfile());136 userReg.register MDProfile(pDesc, RegistryTestHelper.getTestProfile());133 userReg.register(cDesc, RegistryTestHelper.getTestComponent()); 134 publicReg.register(cDesc, RegistryTestHelper.getTestComponent()); 135 publicReg.register(pDesc, RegistryTestHelper.getTestProfile()); 136 userReg.register(pDesc, RegistryTestHelper.getTestProfile()); 137 137 assertEquals(1, userReg.getComponentDescriptions().size()); 138 138 assertEquals(1, userReg.getProfileDescriptions().size()); … … 181 181 assertEquals(0, register.getComponentDescriptions().size()); 182 182 assertEquals(0, register.getProfileDescriptions().size()); 183 register.register MDProfile(description, RegistryTestHelper.getTestProfile());183 register.register(description, RegistryTestHelper.getTestProfile()); 184 184 description = new ProfileDescription(); 185 185 description.setName("Aap2"); 186 186 String id2 = "Aap2" + System.currentTimeMillis(); 187 187 description.setId(id2); 188 register.register MDProfile(description, RegistryTestHelper.getTestProfile());188 register.register(description, RegistryTestHelper.getTestProfile()); 189 189 190 190 assertEquals(0, register.getComponentDescriptions().size()); … … 334 334 CMDComponentSpec testProfile = RegistryTestHelper.getTestProfile(); 335 335 336 register.register MDProfile(description, testProfile);336 register.register(description, testProfile); 337 337 338 338 assertEquals(1, register.getProfileDescriptions().size()); … … 365 365 CMDComponentSpec testComp = RegistryTestHelper.getTestComponent(); 366 366 367 registry.register MDComponent(description, testComp);367 registry.register(description, testComp); 368 368 try { 369 369 registry.deleteMDComponent(description.getId(), new DummyPrincipal("Fake User"), false); … … 395 395 CMDComponentSpec testComp = RegistryTestHelper.getTestComponent(); 396 396 397 registry.register MDComponent(description, testComp);397 registry.register(description, testComp); 398 398 try { 399 399 registry.deleteMDComponent(description.getId(), USER_CREDS.getPrincipal(), false); … … 406 406 407 407 registry = ComponentRegistryFactory.getInstance().getComponentRegistry(true, USER_CREDS); //user registry 408 registry.register MDComponent(description, testComp);408 registry.register(description, testComp); 409 409 assertEquals(1, registry.getComponentDescriptions().size()); 410 410 registry.deleteMDComponent(description.getId(), USER_CREDS.getPrincipal(), false); //user workspace can always delete … … 426 426 CMDComponentSpec testComp = RegistryTestHelper.getTestProfile(); 427 427 428 registry.register MDProfile(description, testComp);428 registry.register(description, testComp); 429 429 try { 430 430 registry.deleteMDProfile(description.getId(), USER_CREDS.getPrincipal()); … … 437 437 438 438 registry = ComponentRegistryFactory.getInstance().getComponentRegistry(true, USER_CREDS); //user registry 439 registry.register MDProfile(description, testComp);439 registry.register(description, testComp); 440 440 assertEquals(1, registry.getProfileDescriptions().size()); 441 441 registry.deleteMDProfile(description.getId(), USER_CREDS.getPrincipal()); //user workspace can always delete … … 452 452 description.setDescription("MyDescription"); 453 453 CMDComponentSpec testComponent = RegistryTestHelper.getTestComponent(); 454 registry.register MDComponent(description, testComponent);454 registry.register(description, testComponent); 455 455 456 456 assertEquals(1, registry.getComponentDescriptions().size()); … … 458 458 assertEquals("MyDescription", desc.getDescription()); 459 459 desc.setDescription("NewDesc"); 460 try { 461 registry.update(desc, USER_CREDS.getPrincipal(), testComponent); 462 fail("Should have failed, only admin users are allowed to update"); 463 } catch (UserUnauthorizedException e) { 464 } 465 registry.update(desc, PRINCIPAL_ADMIN, testComponent); 460 registry.update(desc, testComponent); 466 461 467 462 registry = getTestRegistry(getRegistryDir()); … … 478 473 cd.setName("Y"); 479 474 CMDComponentSpec testComponent = RegistryTestHelper.getTestComponent(); 480 registry.register MDComponent(cd, testComponent);475 registry.register(cd, testComponent); 481 476 482 477 List<ProfileDescription> result = registry.getUsageInProfiles(cd.getId()); … … 489 484 reference.setComponentId(cd.getId()); 490 485 testProfile.getCMDComponent().get(0).getCMDComponent().add(reference); 491 registry.register MDProfile(pd, testProfile);486 registry.register(pd, testProfile); 492 487 493 488 result = registry.getUsageInProfiles(cd.getId()); … … 500 495 ComponentDescription cd = ComponentDescription.createNewDescription(); 501 496 cd.setName("Y"); 502 registry.register MDComponent(cd, RegistryTestHelper.getTestComponent());497 registry.register(cd, RegistryTestHelper.getTestComponent()); 503 498 504 499 List<ComponentDescription> result = registry.getUsageInComponents(cd.getId()); … … 511 506 reference.setComponentId(cd.getId()); 512 507 testComponent.getCMDComponent().get(0).getCMDComponent().add(reference); 513 registry.register MDComponent(cd2, testComponent);508 registry.register(cd2, testComponent); 514 509 515 510 ComponentDescription cd3 = ComponentDescription.createNewDescription(); … … 519 514 reference.setComponentId(cd.getId()); 520 515 testComponent.getCMDComponent().get(0).getCMDComponent().add(reference); 521 registry.register MDComponent(cd3, testComponent);516 registry.register(cd3, testComponent); 522 517 523 518 result = registry.getUsageInComponents(cd.getId()); -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/frontend/FileInfoTest.java
r671 r836 11 11 import org.junit.Test; 12 12 13 import clarin.cmdi.componentregistry.ComponentRegistryImplTest;14 13 import clarin.cmdi.componentregistry.ComponentRegistryTestCase; 15 14 import clarin.cmdi.componentregistry.Configuration; -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r640 r836 9 9 10 10 import java.io.ByteArrayInputStream; 11 import java.util.Date; 11 12 import java.util.List; 12 13 … … 20 21 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 21 22 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 23 import clarin.cmdi.componentregistry.model.AbstractDescription; 22 24 import clarin.cmdi.componentregistry.model.ComponentDescription; 23 25 import clarin.cmdi.componentregistry.model.ProfileDescription; … … 53 55 public void testGetUserComponents() throws Exception { 54 56 fillUp(); 55 List<ComponentDescription> response = getAuthenticatedResource( 56 getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept(MediaType.APPLICATION_XML).get( 57 COMPONENT_LIST_GENERICTYPE); 57 List<ComponentDescription> response = getUserComponents(); 58 58 assertEquals(0, response.size()); 59 59 response = getAuthenticatedResource(getResource().path("/registry/components")).accept(MediaType.APPLICATION_JSON).get( … … 275 275 @Test 276 276 public void testRegisterUserspaceProfile() throws Exception { 277 List<ProfileDescription> profiles = getAuthenticatedResource( 278 getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).accept(MediaType.APPLICATION_XML).get( 279 PROFILE_LIST_GENERICTYPE); 277 List<ProfileDescription> profiles = getUserProfiles(); 280 278 assertEquals("user registered profiles", 0, profiles.size()); 281 assertEquals("public registered profiles", 0, getAuthenticatedResource("/registry/profiles").accept(MediaType.APPLICATION_XML).get( 282 PROFILE_LIST_GENERICTYPE).size()); 279 assertEquals("public registered profiles", 0, getPublicProfiles().size()); 283 280 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 284 281 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")) … … 296 293 assertEquals("http://localhost:9998/registry/profiles/" + profileDesc.getId() + "?userspace=true", profileDesc.getHref()); 297 294 298 profiles = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).accept( 299 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 295 profiles = getUserProfiles(); 300 296 assertEquals(1, profiles.size()); 301 assertEquals(0, getAuthenticatedResource("/registry/profiles").accept(MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE) 302 .size()); 297 assertEquals(0, getPublicProfiles().size()); 303 298 ClientResponse cResponse = getResource().path("/registry/profiles/" + profileDesc.getId()).accept(MediaType.APPLICATION_XML).get( 304 299 ClientResponse.class); … … 327 322 assertEquals(200, cResponse.getStatus()); 328 323 329 profiles = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).accept( 324 profiles = getUserProfiles(); 325 assertEquals(0, profiles.size()); 326 } 327 328 private List<ProfileDescription> getPublicProfiles() { 329 return getAuthenticatedResource("/registry/profiles").accept(MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 330 } 331 332 private List<ProfileDescription> getUserProfiles() { 333 return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).accept( 330 334 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 331 assertEquals(0, profiles.size());332 335 } 333 336 334 337 private FormDataMultiPart createFormData(Object content) { 338 return createFormData(content, "My Test"); 339 } 340 341 private FormDataMultiPart createFormData(Object content, String description) { 335 342 FormDataMultiPart form = new FormDataMultiPart(); 336 343 form.field(ComponentRegistryRestService.DATA_FORM_FIELD, content, MediaType.APPLICATION_OCTET_STREAM_TYPE); 337 344 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "Test1"); 338 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test");345 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, description); 339 346 form.field(ComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain"); 340 347 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); … … 344 351 @Test 345 352 public void testRegisterWithUserComponents() throws Exception { 346 ComponentRegistry userRegistry = ComponentRegistryFactory.getInstance().getComponentRegistry(true, DummyPrincipal.DUMMY_CREDENTIALS); 353 ComponentRegistry userRegistry = ComponentRegistryFactory.getInstance() 354 .getComponentRegistry(true, DummyPrincipal.DUMMY_CREDENTIALS); 347 355 String content = ""; 348 356 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; … … 369 377 assertFalse(response.isRegistered()); 370 378 assertEquals(1, response.getErrors().size()); 371 assertEquals("referenced component cannot be found in the published components: "+ compDesc1.getName()+" ("+ compDesc1.getId()+")", response.getErrors().get(0)); 379 assertEquals("referenced component cannot be found in the published components: " + compDesc1.getName() + " (" + compDesc1.getId() 380 + ")", response.getErrors().get(0)); 372 381 373 382 response = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).type( … … 390 399 assertFalse(response.isRegistered()); 391 400 assertEquals(1, response.getErrors().size()); 392 assertEquals("referenced component cannot be found in the published components: " + comp2.getName()+" ("+ comp2.getId()+")", response.getErrors().get(0)); 401 assertEquals("referenced component cannot be found in the published components: " + comp2.getName() + " (" + comp2.getId() + ")", 402 response.getErrors().get(0)); 393 403 394 404 response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")).type( … … 399 409 @Test 400 410 public void testRegisterUserspaceComponent() throws Exception { 401 List<ComponentDescription> components = getAuthenticatedResource( 402 getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept(MediaType.APPLICATION_XML).get( 403 COMPONENT_LIST_GENERICTYPE); 411 List<ComponentDescription> components = getUserComponents(); 404 412 assertEquals("user registered components", 0, components.size()); 405 assertEquals("public registered components", 0, getAuthenticatedResource("/registry/components").accept(MediaType.APPLICATION_XML) 406 .get(COMPONENT_LIST_GENERICTYPE).size()); 413 assertEquals("public registered components", 0, getPublicComponents().size()); 407 414 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 408 415 … … 424 431 assertEquals(url + "registry/components/" + desc.getId() + "?userspace=true", desc.getHref()); 425 432 426 components = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept( 427 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 433 components = getUserComponents(); 428 434 assertEquals(1, components.size()); 429 assertEquals(0, getAuthenticatedResource("/registry/components").accept(MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE) 430 .size()); 435 assertEquals(0, getPublicComponents().size()); 431 436 432 437 ClientResponse cResponse = getResource().path("/registry/components/" + desc.getId()).accept(MediaType.APPLICATION_XML).get( 433 438 ClientResponse.class); 434 439 assertEquals(204, cResponse.getStatus()); 435 CMDComponentSpec spec = getAuthenticatedResource( 436 getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")).accept( 437 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 440 CMDComponentSpec spec = getUserComponent(desc); 438 441 assertNotNull(spec); 439 442 … … 455 458 assertEquals(200, cResponse.getStatus()); 456 459 457 components = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept( 460 components = getUserComponents(); 461 assertEquals(0, components.size()); 462 } 463 464 @Test 465 public void testUpdateComponent() throws Exception { 466 List<ComponentDescription> components = getUserComponents(); 467 assertEquals("user registered components", 0, components.size()); 468 assertEquals("public registered components", 0, getPublicComponents().size()); 469 470 FormDataMultiPart form = createFormData(RegistryTestHelper.getComponentTestContent()); 471 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")) 472 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 473 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 474 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 475 assertTrue(response.isRegistered()); 476 assertFalse(response.isProfile()); 477 assertTrue(response.isInUserSpace()); 478 ComponentDescription desc = (ComponentDescription) response.getDescription(); 479 assertNotNull(desc); 480 assertEquals("Test1", desc.getName()); 481 assertEquals("My Test", desc.getDescription()); 482 Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate()); 483 CMDComponentSpec spec = getUserComponent(desc); 484 assertNotNull(spec); 485 assertEquals("Access", spec.getCMDComponent().get(0).getName()); 486 components = getUserComponents(); 487 assertEquals(1, components.size()); 488 assertEquals(0, getPublicComponents().size()); 489 490 //Now update 491 form = createFormData(RegistryTestHelper.getComponentTestContent("TESTNAME"), "UPDATE DESCRIPTION!"); 492 cResponse = getAuthenticatedResource( 493 getResource().path("/registry/components/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type( 494 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 495 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 496 response = cResponse.getEntity(RegisterResponse.class); 497 assertTrue(response.isRegistered()); 498 assertFalse(response.isProfile()); 499 assertTrue(response.isInUserSpace()); 500 desc = (ComponentDescription) response.getDescription(); 501 assertNotNull(desc); 502 assertEquals("Test1", desc.getName()); 503 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 504 Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate()); 505 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 506 507 spec = getUserComponent(desc); 508 assertNotNull(spec); 509 assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName()); 510 components = getUserComponents(); 511 assertEquals(1, components.size()); 512 assertEquals(0, getPublicComponents().size()); 513 } 514 515 @Test 516 public void testUpdateProfile() throws Exception { 517 List<ProfileDescription> profiles = getUserProfiles(); 518 assertEquals(0, profiles.size()); 519 assertEquals(0, getPublicProfiles().size()); 520 521 FormDataMultiPart form = createFormData(RegistryTestHelper.getTestProfileContent()); 522 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(USERSPACE_PARAM, "true")) 523 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 524 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 525 RegisterResponse response = cResponse.getEntity(RegisterResponse.class); 526 assertTrue(response.isRegistered()); 527 assertTrue(response.isProfile()); 528 assertTrue(response.isInUserSpace()); 529 ProfileDescription desc = (ProfileDescription) response.getDescription(); 530 assertNotNull(desc); 531 assertEquals("Test1", desc.getName()); 532 assertEquals("My Test", desc.getDescription()); 533 Date firstDate = AbstractDescription.getDate(desc.getRegistrationDate()); 534 CMDComponentSpec spec = getUserProfile(desc); 535 assertNotNull(spec); 536 assertEquals("Actor", spec.getCMDComponent().get(0).getName()); 537 profiles = getUserProfiles(); 538 assertEquals(1, profiles.size()); 539 assertEquals(0, getPublicComponents().size()); 540 541 //Now update 542 form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"), "UPDATE DESCRIPTION!"); 543 cResponse = getAuthenticatedResource( 544 getResource().path("/registry/profiles/" + desc.getId() + "/update").queryParam(USERSPACE_PARAM, "true")).type( 545 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 546 assertEquals(ClientResponse.Status.OK.getStatusCode(), cResponse.getStatus()); 547 response = cResponse.getEntity(RegisterResponse.class); 548 assertTrue(response.isRegistered()); 549 assertTrue(response.isProfile()); 550 assertTrue(response.isInUserSpace()); 551 desc = (ProfileDescription) response.getDescription(); 552 assertNotNull(desc); 553 assertEquals("Test1", desc.getName()); 554 assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); 555 Date secondDate = AbstractDescription.getDate(desc.getRegistrationDate()); 556 assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); 557 558 spec = getUserProfile(desc); 559 assertNotNull(spec); 560 assertEquals("TESTNAME", spec.getCMDComponent().get(0).getName()); 561 profiles = getUserProfiles(); 562 assertEquals(1, profiles.size()); 563 assertEquals(0, getPublicComponents().size()); 564 } 565 566 private CMDComponentSpec getUserComponent(ComponentDescription desc) { 567 return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")) 568 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 569 } 570 571 private CMDComponentSpec getUserProfile(ProfileDescription desc) { 572 return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()).queryParam(USERSPACE_PARAM, "true")) 573 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 574 } 575 576 private List<ComponentDescription> getPublicComponents() { 577 return getAuthenticatedResource("/registry/components").accept(MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 578 } 579 580 private List<ComponentDescription> getUserComponents() { 581 return getAuthenticatedResource(getResource().path("/registry/components").queryParam(USERSPACE_PARAM, "true")).accept( 458 582 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 459 assertEquals(0, components.size());460 583 } 461 584 … … 547 670 assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0)); 548 671 } 549 550 // @Test551 // public void testPingSession() throws Exception {552 // ClientResponse clientResponse = getAuthenticatedResource("/registry/pingSession").get(ClientResponse.class);553 // assertEquals(200, clientResponse.getStatus());554 // assertEquals("<session stillActive=\"true\"/>", clientResponse.getEntity(String.class));555 // clientResponse = getResource().path("/registry/pingSession").get(ClientResponse.class);556 // assertEquals(200, clientResponse.getStatus());557 // assertEquals("<session stillActive=\"false\"/>", clientResponse.getEntity(String.class));672 673 // @Test 674 // public void testPingSession() throws Exception { 675 // ClientResponse clientResponse = getAuthenticatedResource("/registry/pingSession").get(ClientResponse.class); 676 // assertEquals(200, clientResponse.getStatus()); 677 // assertEquals("<session stillActive=\"true\"/>", clientResponse.getEntity(String.class)); 678 // clientResponse = getResource().path("/registry/pingSession").get(ClientResponse.class); 679 // assertEquals(200, clientResponse.getStatus()); 680 // assertEquals("<session stillActive=\"false\"/>", clientResponse.getEntity(String.class)); 558 681 // TODO Patrick enable test and client, need to update dependencies first. Add some test with empty session. 559 // }560 // @Override561 // public Client client() {562 // DefaultApacheHttpClientConfig config = new563 // DefaultApacheHttpClientConfig();564 // config565 // .setProperty("com.sun.jersey.impl.client.httpclient.handleCookies",566 // true);567 // ApacheHttpClient c = ApacheHttpClient.create(config);568 //569 // return ;570 // }682 // } 683 // @Override 684 // public Client client() { 685 // DefaultApacheHttpClientConfig config = new 686 // DefaultApacheHttpClientConfig(); 687 // config 688 // .setProperty("com.sun.jersey.impl.client.httpclient.handleCookies", 689 // true); 690 // ApacheHttpClient c = ApacheHttpClient.create(config); 691 // 692 // return ; 693 // } 571 694 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java
r622 r836 47 47 desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id); 48 48 CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema()); 49 testRegistry.register MDComponent(desc, spec);49 testRegistry.register(desc, spec); 50 50 return desc; 51 51 } 52 52 53 53 public static InputStream getTestProfileContent() { 54 return getTestProfileContent("Actor"); 55 } 56 57 public static InputStream getTestProfileContent(String name) { 54 58 String profileContent = ""; 55 59 profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 57 61 profileContent += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; 58 62 profileContent += " <Header />\n"; 59 profileContent += " <CMD_Component name=\" Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";63 profileContent += " <CMD_Component name=\""+name+"\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n"; 60 64 profileContent += " <AttributeList>\n"; 61 65 profileContent += " <Attribute>\n"; … … 94 98 desc.setHref("link:" + ComponentRegistry.REGISTRY_ID + id); 95 99 CMDComponentSpec spec = MDMarshaller.unmarshal(CMDComponentSpec.class, content, MDMarshaller.getCMDComponentSchema()); 96 testRegistry.register MDProfile(desc, spec);100 testRegistry.register(desc, spec); 97 101 return desc; 98 102 } … … 103 107 104 108 public static InputStream getComponentTestContent() { 109 return getComponentTestContent("Access"); 110 } 111 112 public static InputStream getComponentTestContent(String componentName) { 105 113 String compContent = ""; 106 114 compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; … … 111 119 compContent += " <Header/>\n"; 112 120 compContent += " \n"; 113 compContent += " <CMD_Component name=\" Access\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";121 compContent += " <CMD_Component name=\"" + componentName + "\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n"; 114 122 compContent += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; 115 123 compContent += " <CMD_Element name=\"Date\">\n";
Note: See TracChangeset
for help on using the changeset viewer.