Changeset 1870
- Timestamp:
- 04/10/12 13:46:22 (12 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1869 r1870 645 645 return new CMDComponentSpecExpanderDbImpl(this); 646 646 } 647 648 @Override 649 public String toString() { 650 return getName(); 651 } 647 652 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r1863 r1870 1 1 package clarin.cmdi.componentregistry.rest; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 import clarin.cmdi.componentregistry.ComponentRegistryException; 5 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 6 import clarin.cmdi.componentregistry.DeleteFailedException; 7 import clarin.cmdi.componentregistry.UserCredentials; 8 import clarin.cmdi.componentregistry.UserUnauthorizedException; 9 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 10 import clarin.cmdi.componentregistry.model.AbstractDescription; 11 import clarin.cmdi.componentregistry.model.Comment; 12 import clarin.cmdi.componentregistry.model.CommentResponse; 13 import clarin.cmdi.componentregistry.model.ComponentDescription; 14 import clarin.cmdi.componentregistry.model.ProfileDescription; 15 import clarin.cmdi.componentregistry.model.RegisterResponse; 16 import com.sun.jersey.multipart.FormDataParam; 17 import com.sun.jersey.spi.inject.Inject; 3 18 import java.io.IOException; 4 19 import java.io.InputStream; … … 9 24 import java.util.Arrays; 10 25 import java.util.List; 11 12 26 import javax.servlet.http.HttpServletRequest; 13 27 import javax.ws.rs.Consumes; … … 25 39 import javax.ws.rs.core.MediaType; 26 40 import javax.ws.rs.core.Response; 41 import javax.ws.rs.core.Response.Status; 27 42 import javax.ws.rs.core.SecurityContext; 28 43 import javax.ws.rs.core.StreamingOutput; 29 44 import javax.ws.rs.core.UriInfo; 30 import javax.ws.rs.core.Response.Status;31 32 45 import org.slf4j.Logger; 33 46 import org.slf4j.LoggerFactory; 34 35 import clarin.cmdi.componentregistry.ComponentRegistry;36 import clarin.cmdi.componentregistry.ComponentRegistryException;37 import clarin.cmdi.componentregistry.ComponentRegistryFactory;38 import clarin.cmdi.componentregistry.DeleteFailedException;39 import clarin.cmdi.componentregistry.UserCredentials;40 import clarin.cmdi.componentregistry.UserUnauthorizedException;41 import clarin.cmdi.componentregistry.components.CMDComponentSpec;42 import clarin.cmdi.componentregistry.model.AbstractDescription;43 import clarin.cmdi.componentregistry.model.Comment;44 import clarin.cmdi.componentregistry.model.ComponentDescription;45 import clarin.cmdi.componentregistry.model.ProfileDescription;46 import clarin.cmdi.componentregistry.model.CommentResponse;47 import clarin.cmdi.componentregistry.model.RegisterResponse;48 49 import com.sun.jersey.multipart.FormDataParam;50 import com.sun.jersey.spi.inject.Inject;51 47 52 48 @Path("/registry") … … 134 130 @Path("/components/{componentId}") 135 131 @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 136 public CMDComponentSpecgetRegisteredComponent(@PathParam("componentId") String componentId,132 public Response getRegisteredComponent(@PathParam("componentId") String componentId, 137 133 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException { 138 134 LOG.info("Component with id: " + componentId + " is requested."); 139 return getRegistry(userspace).getMDComponent(componentId); 135 CMDComponentSpec mdComponent = getRegistry(userspace).getMDComponent(componentId); 136 if (mdComponent == null) { 137 return Response.status(Status.NOT_FOUND).build(); 138 } else { 139 return Response.ok(mdComponent).build(); 140 } 140 141 } 141 142 … … 212 213 @Path("/profiles/{profileId}") 213 214 @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 214 public CMDComponentSpecgetRegisteredProfile(@PathParam("profileId") String profileId,215 public Response getRegisteredProfile(@PathParam("profileId") String profileId, 215 216 @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException { 216 217 LOG.info("Profile with id: " + profileId + " is requested."); 217 return getRegistry(userspace).getMDProfile(profileId); 218 CMDComponentSpec mdProfile = getRegistry(userspace).getMDProfile(profileId); 219 if (mdProfile == null) { 220 return Response.status(Status.NOT_FOUND).build(); 221 } else { 222 return Response.ok(mdProfile).build(); 223 } 218 224 } 219 225 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r1836 r1870 347 347 profile = getResource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get( 348 348 CMDComponentSpec.class); 349 fail("Exception should have been thrown resource does not exist, HttpStatusCode 204");349 fail("Exception should have been thrown resource does not exist, HttpStatusCode 404"); 350 350 } catch (UniformInterfaceException e) { 351 assertEquals( 204, e.getResponse().getStatus());351 assertEquals(404, e.getResponse().getStatus()); 352 352 } 353 353 } … … 558 558 cResponse = getResource().path("/registry/profiles/" + profileDesc.getId()).accept(MediaType.APPLICATION_XML).get( 559 559 ClientResponse.class); 560 // Should return 204 = no content561 assertEquals( 204, cResponse.getStatus());560 // Should return 404 = not found 561 assertEquals(404, cResponse.getStatus()); 562 562 CMDComponentSpec spec = getAuthenticatedResource( 563 563 getResource().path("/registry/profiles/" + profileDesc.getId()).queryParam(USERSPACE_PARAM, "true")).accept( … … 698 698 cResponse = getResource().path("/registry/components/" + desc.getId()).accept(MediaType.APPLICATION_XML).get( 699 699 ClientResponse.class); 700 // Should return 204 = no content701 assertEquals( 204, cResponse.getStatus());700 // Should return 404 = not found 701 assertEquals(404, cResponse.getStatus()); 702 702 CMDComponentSpec spec = getUserComponent(desc); 703 703 assertNotNull(spec); … … 966 966 /** 967 967 * Two elements on the same level with the same name violates schematron rule, and should fail validation 968 * @throws Exception 968 * 969 * @throws Exception 969 970 */ 970 971 @Test
Note: See TracChangeset
for help on using the changeset viewer.