Changeset 207
- Timestamp:
- 03/03/10 13:08:06 (14 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry
- Files:
-
- 4 added
- 15 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/pom.xml
r172 r207 73 73 <groupId>com.sun.jersey</groupId> 74 74 <artifactId>jersey-server</artifactId> 75 <version>1.1. 2-ea</version>75 <version>1.1.5</version> 76 76 </dependency> 77 77 <dependency> <!-- Needed for "automatic" json support --> 78 78 <groupId>com.sun.jersey</groupId> 79 79 <artifactId>jersey-json</artifactId> 80 <version>1.1. 2-ea</version>80 <version>1.1.5</version> 81 81 <exclusions> 82 <!--Jersey has dependencies with different group ids therefore maven cannot resolve the conflict 83 and gives me both jars (two of stax and two of jaxb-impl). Excluding them manually to overcome the problem --> 84 <exclusion> 82 <!-- 83 Jersey has dependencies with different group ids therefore maven cannot resolve the conflict and gives me both 84 jars (two of stax and two of jaxb-impl). Excluding them manually to overcome the problem 85 --> 86 <exclusion> 85 87 <groupId>stax</groupId> 86 <artifactId>stax-api</artifactId> 87 </exclusion> 88 <exclusion> 88 <artifactId>stax-api</artifactId> 89 </exclusion> 90 <exclusion> 89 91 <groupId>com.sun.xml.bind</groupId> 90 <artifactId>jaxb-impl</artifactId> 92 <artifactId>jaxb-impl</artifactId> 91 93 </exclusion> 92 94 </exclusions> … … 95 97 <groupId>com.sun.jersey.contribs</groupId> 96 98 <artifactId>jersey-multipart</artifactId> 97 <version>1.1. 2-ea</version>99 <version>1.1.5</version> 98 100 </dependency> 99 101 <dependency> <!-- Client used for RegistryFiller command line tool--> 100 102 <groupId>com.sun.jersey</groupId> 101 103 <artifactId>jersey-client</artifactId> 102 <version>1.1.2-ea</version> 103 </dependency> 104 <version>1.1.5</version> 105 </dependency> 106 <dependency> 107 <groupId>net.sf.saxon</groupId> 108 <artifactId>saxon-dom</artifactId> 109 <version>8.7</version> 110 </dependency> 111 104 112 <dependency> 105 113 <groupId>com.sun.jersey</groupId> 106 114 <artifactId>jersey-test-framework</artifactId> 107 <version>1.1. 2-ea</version>115 <version>1.1.5</version> 108 116 <scope>test</scope> 109 117 <exclusions> … … 116 124 <artifactId>grizzly-servlet-webserver</artifactId> 117 125 </exclusion> 118 <exclusion> 126 <exclusion> 119 127 <groupId>com.sun.xml.bind</groupId> 120 <artifactId>jaxb-impl</artifactId> 128 <artifactId>jaxb-impl</artifactId> 121 129 </exclusion> 122 130 </exclusions> … … 127 135 <version>1.0.1</version> 128 136 </dependency> 137 <dependency> 138 <groupId>de.mpg.mpgaai</groupId> 139 <artifactId>mpgaai-jaas</artifactId> 140 <version>1.3.2</version> 141 </dependency> 142 143 <dependency> 144 <groupId>de.mpg.mpgaai</groupId> 145 <artifactId>mpgaai-shhaa</artifactId> 146 <version>1.0.2</version> 147 </dependency> 148 129 149 </dependencies> 130 150 -
ComponentRegistry/trunk/ComponentRegistry/properties/flexindex.properties
r34 r207 1 1 title=Clarin Component Registry 2 version_major= 92 version_major=10 3 3 version_minor=0 4 version_revision= 1244 version_revision=0 5 5 width=100% 6 6 height=100% -
ComponentRegistry/trunk/ComponentRegistry/src/main/assembly/registryFiller.xml
r89 r207 17 17 <includes> 18 18 <include>log4j.properties</include> <!-- Copy log4j to the bin dir to make it a bit easier to change values in it --> 19 <include>registry.properties</include> <!-- Needs to be adjusted before running scripts --> 19 20 </includes> 20 21 <outputDirectory>bin</outputDirectory> -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java
r107 r207 1 1 package clarin.cmdi.componentregistry; 2 2 3 import java.io.IOException; 4 import java.security.Principal; 3 5 import java.util.List; 4 6 … … 10 12 11 13 public static final String REGISTRY_ID = "clarin.eu:cr1:"; 12 14 13 15 List<ComponentDescription> getComponentDescriptions(); 16 14 17 List<ProfileDescription> getProfileDescriptions(); 18 15 19 CMDComponentSpec getMDProfile(String id); 20 16 21 CMDComponentSpec getMDComponent(String id); 22 17 23 List<MDProfile> searchMDProfiles(String searchPattern); 18 24 … … 22 28 */ 23 29 int registerMDProfile(ProfileDescription description, CMDComponentSpec spec); 24 //What about some Credentials or metadata also add in the parameters?25 30 26 31 int registerMDComponent(ComponentDescription description, CMDComponentSpec spec); 27 32 28 33 String getMDProfileAsXml(String profileId); 34 29 35 String getMDProfileAsXsd(String profileId); 30 36 31 37 String getMDComponentAsXml(String componentId); 38 32 39 String getMDComponentAsXsd(String componentId); 33 40 34 //Remove from registry? 41 /** 42 * 43 * @param profileId 44 * @param principal 45 * @throws IOException 46 * @throws UserUnauthorizedException thrown when principal does not match creator of profile 47 */ 48 void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException; 49 50 /** 51 * 52 * @param componentId 53 * @param principal 54 * @throws IOException 55 * @throws UserUnauthorizedException thrown when principal does not match creator of component 56 */ 57 void deleteMDComponent(String componentId, Principal principal) throws IOException, UserUnauthorizedException; 58 35 59 //getElements? 36 60 //List<ConceptLinks> getConceptLinks(String componentId, String xpath); We only need xpath I think it contains the componentId's -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryImpl.java
r136 r207 8 8 import java.io.StringWriter; 9 9 import java.io.Writer; 10 import java.security.Principal; 10 11 import java.util.ArrayList; 11 12 import java.util.Collection; … … 20 21 import org.apache.commons.io.FileUtils; 21 22 import org.apache.commons.io.IOUtils; 22 import org.apache.commons.io.filefilter.TrueFileFilter; 23 import org.apache.commons.io.filefilter.IOFileFilter; 24 import org.apache.commons.io.filefilter.NameFileFilter; 25 import org.apache.commons.io.filefilter.NotFileFilter; 23 26 import org.apache.commons.io.filefilter.WildcardFileFilter; 24 27 import org.apache.commons.lang.StringUtils; … … 119 122 private Map<String, ProfileDescription> loadProfileDescriptions() { 120 123 Collection files = FileUtils.listFiles(configuration.getProfileDir(), new WildcardFileFilter(DESCRIPTION_FILE_NAME), 121 TrueFileFilter.TRUE);124 DIRS_WITH_DESCRIPTIONS); 122 125 Map<String, ProfileDescription> result = new HashMap<String, ProfileDescription>(); 123 126 for (Iterator iterator = files.iterator(); iterator.hasNext();) { … … 130 133 } 131 134 135 private final static IOFileFilter DIRS_WITH_DESCRIPTIONS = new NotFileFilter(new NameFileFilter(Configuration.DELETED_DIR_NAME)); 136 132 137 private Map<String, ComponentDescription> loadComponentDescriptions() { 133 Collection files = FileUtils.listFiles(getComponentDir(), new WildcardFileFilter(DESCRIPTION_FILE_NAME), TrueFileFilter.TRUE);138 Collection files = FileUtils.listFiles(getComponentDir(), new WildcardFileFilter(DESCRIPTION_FILE_NAME), DIRS_WITH_DESCRIPTIONS); 134 139 Map<String, ComponentDescription> result = new HashMap<String, ComponentDescription>(); 135 140 for (Iterator iterator = files.iterator(); iterator.hasNext();) { … … 310 315 } 311 316 317 public void deleteMDProfile(String profileId, Principal principal) throws IOException, UserUnauthorizedException { 318 ProfileDescription desc = profileDescriptions.get(profileId); 319 if (desc != null) { 320 checkAuthorisation(desc, principal); 321 File profileFile = getProfileFile(profileId); 322 if (profileFile.exists()) { 323 FileUtils.moveDirectoryToDirectory(profileFile.getParentFile(), configuration.getProfileDeletionDir(), true); 324 profileDescriptions.remove(profileId); 325 profilesCache.remove(profileId); 326 } // else no profile so nothing to delete 327 } 328 } 329 330 private void checkAuthorisation(AbstractDescription desc, Principal principal) throws UserUnauthorizedException { 331 if (!principal.getName().equals(desc.getCreatorName())) { 332 throw new UserUnauthorizedException("Unauthorized operation user: " + principal.getName() 333 + " was not the creator of profile/component (description=" + desc + ")."); 334 } 335 } 336 337 public void deleteMDComponent(String componentId, Principal principal) throws IOException, UserUnauthorizedException { 338 ComponentDescription desc = componentDescriptions.get(componentId); 339 if (desc != null) { 340 checkAuthorisation(desc, principal); 341 File componentFile = getComponentFile(componentId); 342 if (componentFile.exists()) { 343 FileUtils.moveDirectoryToDirectory(componentFile.getParentFile(), configuration.getComponentDeletionDir(), true); 344 componentDescriptions.remove(componentId); 345 componentsCache.remove(componentId); 346 } // else no component so nothing to delete 347 } 348 } 349 312 350 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/Configuration.java
r55 r207 8 8 public class Configuration { 9 9 10 public static final String DELETED_DIR_NAME = "deleted"; 11 10 12 private final static Logger LOG = LoggerFactory.getLogger(Configuration.class); 11 13 … … 13 15 private File componentDir; 14 16 private File profileDir; 17 private File profileDeletionDir; 18 private File componentDeletionDir; 15 19 16 20 public void init() { … … 19 23 componentDir = new File(registryRoot, "components"); 20 24 isValid &= validateAndCreate(componentDir); 25 componentDeletionDir = new File(componentDir, DELETED_DIR_NAME); 26 isValid &= validateAndCreate(componentDeletionDir); 21 27 profileDir = new File(registryRoot, "profiles"); 22 28 isValid &= validateAndCreate(profileDir); 29 profileDeletionDir = new File(profileDir, DELETED_DIR_NAME); 30 isValid &= validateAndCreate(profileDeletionDir); 23 31 if (isValid) { 24 32 LOG.info("Initialized Component Registry succesfully. Registry is located in: "+registryRoot); … … 51 59 return profileDir; 52 60 } 61 62 public File getProfileDeletionDir() { 63 return profileDeletionDir; 64 } 65 66 public File getComponentDeletionDir() { 67 return componentDeletionDir; 68 } 53 69 54 70 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/AbstractDescription.java
r127 r207 21 21 private String registrationDate; 22 22 private String creatorName; 23 @XmlElement(namespace ="http://www.w3.org/1999/xlink")23 @XmlElement(namespace = "http://www.w3.org/1999/xlink") 24 24 private String href; 25 25 … … 74 74 @Override 75 75 public String toString() { 76 return "Name=" + getName() + ", id=" + getId() ;76 return "Name=" + getName() + ", id=" + getId() + ", creatorName=" + getCreatorName(); 77 77 } 78 78 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
r127 r207 1 1 package clarin.cmdi.componentregistry.rest; 2 2 3 import java.io.IOException; 3 4 import java.io.InputStream; 4 5 import java.net.URI; 6 import java.security.Principal; 7 import java.util.Arrays; 5 8 import java.util.Date; 6 9 import java.util.List; 7 10 8 11 import javax.ws.rs.Consumes; 12 import javax.ws.rs.DELETE; 9 13 import javax.ws.rs.GET; 10 14 import javax.ws.rs.POST; … … 16 20 import javax.ws.rs.core.MediaType; 17 21 import javax.ws.rs.core.Response; 22 import javax.ws.rs.core.SecurityContext; 18 23 import javax.ws.rs.core.UriInfo; 24 import javax.ws.rs.core.Response.Status; 19 25 20 26 import org.slf4j.Logger; … … 23 29 import clarin.cmdi.componentregistry.ComponentRegistry; 24 30 import clarin.cmdi.componentregistry.ComponentRegistryImpl; 31 import clarin.cmdi.componentregistry.UserUnauthorizedException; 25 32 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 26 33 import clarin.cmdi.componentregistry.model.AbstractDescription; … … 36 43 @Context 37 44 UriInfo uriInfo; 45 @Context 46 SecurityContext security; 38 47 39 48 private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryRestService.class); … … 41 50 public static final String DATA_FORM_FIELD = "data"; 42 51 public static final String NAME_FORM_FIELD = "name"; 43 public static final String CREATOR_NAME_FORM_FIELD = "creatorName";44 52 public static final String DESCRIPTION_FORM_FIELD = "description"; 45 53 public static final String GROUP_FORM_FIELD = "group"; … … 75 83 LOG.info("Component with id: " + componentId + " is requested."); 76 84 return registry.getMDComponent(componentId); 85 } 86 87 @DELETE 88 @Path("/components/{componentId}") 89 public Response deleteRegisteredComponent(@PathParam("componentId") String componentId) { 90 Principal principal = security.getUserPrincipal(); 91 if (principal == null) { 92 throw new IllegalArgumentException("no user principal found."); 93 } 94 LOG.info("Component with id: " + componentId + " set for deletion."); 95 try { 96 registry.deleteMDComponent(componentId, principal); 97 } catch (IOException e) { 98 LOG.info("Component with id: " + componentId + " deletion failed.", e); 99 return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build(); 100 } catch (UserUnauthorizedException e) { 101 LOG.info("Component with id: " + componentId + " deletion failed.", e); 102 return Response.serverError().status(Status.UNAUTHORIZED).build(); 103 } 104 LOG.info("Component with id: " + componentId + " deleted."); 105 return Response.ok().build(); 77 106 } 78 107 … … 102 131 } 103 132 133 @DELETE 134 @Path("/profiles/{profileId}") 135 public Response deleteRegisteredProfile(@PathParam("profileId") String profileId) { 136 Principal principal = security.getUserPrincipal(); 137 if (principal == null) { 138 throw new IllegalArgumentException("no user principal found."); 139 } 140 LOG.info("Profile with id: " + profileId + " set for deletion."); 141 try { 142 registry.deleteMDProfile(profileId, principal); 143 } catch (IOException e) { 144 LOG.info("Profile with id: " + profileId + " deletion failed.", e); 145 return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build(); 146 } catch (UserUnauthorizedException e) { 147 LOG.info("Profile with id: " + profileId + " deletion failed.", e); 148 return Response.serverError().status(Status.UNAUTHORIZED).build(); 149 } 150 LOG.info("Profile with id: " + profileId + " deleted."); 151 return Response.ok().build(); 152 } 153 104 154 @GET 105 155 @Path("/profiles/{profileId}/{rawType}") … … 124 174 @Consumes("multipart/form-data") 125 175 public RegisterResponse registerProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name, 126 @FormDataParam(CREATOR_NAME_FORM_FIELD) String creatorName, @FormDataParam(DESCRIPTION_FORM_FIELD) String description) { 176 @FormDataParam(DESCRIPTION_FORM_FIELD) String description) { 177 Principal principal = security.getUserPrincipal(); 178 if (principal == null) { 179 throw new IllegalArgumentException("no user principal found."); 180 } 127 181 ProfileDescription desc = createNewProfileDescription(); 128 desc.setCreatorName( creatorName);182 desc.setCreatorName(principal.getName()); 129 183 desc.setName(name); 130 184 desc.setDescription(description); 131 185 desc.setRegistrationDate(AbstractDescription.DATE_FORMAT.format(new Date())); 132 186 LOG.info("Trying to register Profile: " + desc); 133 return register(input, desc );187 return register(input, desc, principal); 134 188 } 135 189 … … 139 193 @Consumes("multipart/form-data") 140 194 public RegisterResponse registerComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input, 141 @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(CREATOR_NAME_FORM_FIELD) String creatorName, 142 @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group) { 195 @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description, 196 @FormDataParam(GROUP_FORM_FIELD) String group) { 197 Principal principal = security.getUserPrincipal(); 198 if (principal == null) { 199 throw new IllegalArgumentException("no user principal found."); 200 } 143 201 ComponentDescription desc = createNewComponentDescription(); 144 desc.setCreatorName( creatorName);202 desc.setCreatorName(principal.getName()); 145 203 desc.setName(name); 146 204 desc.setDescription(description); … … 148 206 desc.setRegistrationDate(AbstractDescription.DATE_FORMAT.format(new Date())); 149 207 LOG.info("Trying to register Component: " + desc); 150 return register(input, desc); 151 } 152 153 private RegisterResponse register(InputStream input, AbstractDescription desc) { 154 DescriptionValidator descriptionValidator = new DescriptionValidator(desc); 155 MDValidator validator = new MDValidator(input, desc, registry); 156 RegisterResponse response = new RegisterResponse(); 157 validate(response, descriptionValidator, validator); 158 if (response.getErrors().isEmpty()) { 159 CMDComponentSpec spec = validator.getCMDComponentSpec(); 160 int returnCode = spec.isIsProfile() ? registry.registerMDProfile((ProfileDescription) desc, spec) : registry 161 .registerMDComponent((ComponentDescription) desc, spec); 162 if (returnCode == 0) { 163 response.setRegistered(true); 164 response.setDescription(desc); 208 return register(input, desc, principal); 209 } 210 211 private RegisterResponse register(InputStream input, AbstractDescription desc, Principal principal) { 212 try { 213 DescriptionValidator descriptionValidator = new DescriptionValidator(desc); 214 MDValidator validator = new MDValidator(input, desc, registry); 215 RegisterResponse response = new RegisterResponse(); 216 validate(response, descriptionValidator, validator); 217 if (response.getErrors().isEmpty()) { 218 CMDComponentSpec spec = validator.getCMDComponentSpec(); 219 int returnCode = spec.isIsProfile() ? registry.registerMDProfile((ProfileDescription) desc, spec) : registry 220 .registerMDComponent((ComponentDescription) desc, spec); 221 if (returnCode == 0) { 222 response.setRegistered(true); 223 response.setDescription(desc); 224 } else { 225 response.setRegistered(false); 226 response.addError("Unable to register at this moment. Internal server error."); 227 } 165 228 } else { 229 LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray())); 166 230 response.setRegistered(false); 167 response.addError("Unable to register at this moment. Internal server error.");168 231 } 169 } else { 170 response.setRegistered(false); 171 } 172 response.setIsProfile(desc.isProfile()); 173 return response; 232 response.setIsProfile(desc.isProfile()); 233 return response; 234 } finally { 235 try { 236 input.close();//either we read the input or there was an exception, we need to close it. 237 } catch (IOException e) { 238 LOG.error("Error when closing inputstream: ", e); 239 } 240 } 174 241 } 175 242 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/MDValidator.java
r127 r207 58 58 } 59 59 60 61 60 private void validateComponents(List<CMDComponentType> cmdComponents) { 62 61 for (CMDComponentType cmdComponentType : cmdComponents) { -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryFiller.java
r157 r207 4 4 import java.io.ByteArrayOutputStream; 5 5 import java.io.File; 6 import java.io.FileInputStream; 6 7 import java.io.IOException; 7 8 import java.net.HttpURLConnection; … … 13 14 import java.util.List; 14 15 import java.util.Map; 16 import java.util.Properties; 15 17 import java.util.Set; 16 18 … … 55 57 private RegistryToolHelper helper; 56 58 57 public RegistryFiller(String url) { 59 // Properties: 60 //userName=tomcat 61 //password=tomcat 62 //registryFillerUrl=http://localhost:8080/ComponentRegistry/rest/registry 63 //registryMigrationUrl=http://lux16.mpi.nl:8080/ds/ComponentRegistry/rest/registry 64 Properties properties = new Properties(); 65 static final String FILLER_URL_PROP = "registryFillerUrl"; 66 static final String MIGRATION_URL_PROP = "registryMigrationUrl"; 67 private static final String PASSWORD_PROP = "password"; 68 private static final String USER_NAME_PROP = "userName"; 69 70 public RegistryFiller(String urlPropName) throws IOException { 71 properties.load(new FileInputStream("/registry.properties")); 72 String url = properties.getProperty(urlPropName); 58 73 URI uri = UriBuilder.fromUri(url).build(); 59 74 Client client = Client.create(); … … 61 76 unresolvedComponents = new HashSet<RegObject>(); 62 77 resolvedComponents = new HashMap<RegObject, CMDComponentSpec>(); 63 helper = new RegistryToolHelper(service );78 helper = new RegistryToolHelper(service, properties.getProperty(USER_NAME_PROP), properties.getProperty(PASSWORD_PROP)); 64 79 } 65 80 66 81 /** 67 * RegistryFiller "P.Duin" "Test files" imdi -c /Users/patdui/Workspace/Clarin/metadata/toolkit/components/imdi/component*.xml68 * @param args69 * 70 * Uses a heuristic to resolve components which are linked together through fileName. It will try to find the component with71 * a name equal to the filename (without extension) and set the registered id correct.82 * Uses a heuristic to resolve components which are linked together through fileName. It will try to find the component with a name 83 * equal to the filename (without extension) and set the registered id correct. 84 * @param args RegistryFiller "P.Duin" "Test files" imdi -c 85 * /Users/patdui/Workspace/Clarin/metadata/toolkit/components/imdi/component*.xml 86 * @throws IOException when properties cannot be loaded 72 87 * 73 88 */ 74 public static void main(String[] args) {89 public static void main(String[] args) throws IOException { 75 90 LOG.info("RegistryFiller started with arguments: " + Arrays.toString(args)); 76 91 if (args.length == 0 || args.length < 5) { 77 92 printUsage(); 78 93 } 79 String url = "http://localhost:8080/ComponentRegistry/rest/registry"; 80 RegistryFiller filler = new RegistryFiller(url); 94 RegistryFiller filler = new RegistryFiller(FILLER_URL_PROP); 81 95 String creatorName = args[0]; 82 96 String description = args[1]; … … 108 122 private static void printUsage() { 109 123 System.out.println("usage: <creatorName> <description> <groupType> <-c|-p (components or profiles)> <xml file(s)>"); 124 System.out.println("It also needs a filled in registry.properties"); 110 125 System.exit(0); 111 126 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryMigration.java
r157 r207 2 2 3 3 import java.io.File; 4 import java.io.IOException; 4 5 import java.util.Arrays; 5 6 import java.util.List; … … 21 22 private final static Logger LOG = LoggerFactory.getLogger(RegistryMigration.class); 22 23 private Configuration config; 23 private final String targetUrl;24 24 private ComponentRegistryImpl registry; 25 25 26 26 /* 27 * http://lux16.mpi.nl:8080/ds/ComponentRegistry/rest/registry28 *29 27 * /tmp/ComponentRegistry 30 28 */ 31 public RegistryMigration(String sourceDir, String targetUrl) { 32 this.targetUrl = targetUrl; 29 public RegistryMigration(String sourceDir) { 33 30 config = new Configuration(); 34 31 config.setRegistryRoot(new File(sourceDir)); … … 38 35 } 39 36 40 private void migrate() {41 RegistryFiller filler = new RegistryFiller( targetUrl);37 private void migrate() throws IOException { 38 RegistryFiller filler = new RegistryFiller(RegistryFiller.MIGRATION_URL_PROP); 42 39 addComponents(filler); 43 40 addProfiles(filler); … … 68 65 /** 69 66 * @param args 67 * @throws IOException 70 68 */ 71 public static void main(String[] args) {69 public static void main(String[] args) throws IOException { 72 70 LOG.info("RegistryMigration started with arguments: " + Arrays.toString(args)); 73 if (args.length != 2) {71 if (args.length != 1) { 74 72 printUsage(); 75 73 } 76 RegistryMigration migration = new RegistryMigration(args[0] , args[1]);74 RegistryMigration migration = new RegistryMigration(args[0]); 77 75 migration.migrate(); 78 76 } 79 77 80 78 private static void printUsage() { 81 System.out.println("usage: <source registry directory> <target registry URL>"); 79 System.out.println("usage: <source registry directory>"); 80 System.out.println("It also needs a filled in registry.properties"); 82 81 System.exit(0); 83 82 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/tools/RegistryToolHelper.java
r131 r207 4 4 import java.io.InputStream; 5 5 6 import javax.ws.rs.core.HttpHeaders; 6 7 import javax.ws.rs.core.MediaType; 7 8 … … 13 14 14 15 import com.sun.jersey.api.client.WebResource; 16 import com.sun.jersey.api.client.WebResource.Builder; 17 import com.sun.jersey.core.util.Base64; 15 18 import com.sun.jersey.multipart.FormDataMultiPart; 16 19 … … 22 25 private int failed = 0; 23 26 24 public RegistryToolHelper(WebResource service) { 27 private final String userName; 28 29 private final String password; 30 31 public RegistryToolHelper(WebResource service, String userName, String password) { 25 32 this.service = service; 33 this.userName = userName; 34 this.password = password; 26 35 } 27 36 … … 29 38 FormDataMultiPart form = createForm(input, creatorName, description, name); 30 39 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, group); 31 RegisterResponse response = service.path("/components").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);40 RegisterResponse response = getAuthenticatedResource("/components").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 32 41 handleResult(response); 33 42 } … … 35 44 public void registerProfile(InputStream input, String creatorName, String description, String name) throws IOException { 36 45 FormDataMultiPart form = createForm(input, creatorName, description, name); 37 RegisterResponse response = service.path("/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);46 RegisterResponse response = getAuthenticatedResource("/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form); 38 47 handleResult(response); 39 48 } 49 50 private Builder getAuthenticatedResource(String path) { 51 return service.path(path).header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(userName+":"+password))); 52 } 53 40 54 41 55 private FormDataMultiPart createForm(InputStream input, String creatorName, String description, String name) throws IOException { … … 44 58 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, name); 45 59 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, description); 46 form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, creatorName);47 60 return form; 48 61 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/webapp/WEB-INF/web.xml
r60 r207 5 5 <description>Clarin Metadata Component Registry</description> 6 6 7 <!-- <context-param> 8 <param-name>ShhaaConfigLocation</param-name> 9 <param-value>/WEB-INF/shhaa.xml</param-value> 10 </context-param> --> 7 11 <listener> 8 12 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 9 13 </listener> 14 <!-- 15 filter> <filter-name>AAIFilter</filter-name> <filter-class>de.mpg.aai.shhaa.AuthFilter</filter-class> </filter> 16 <filter-mapping> <filter-name>AAIFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> 17 <listener-class>de.mpg.aai.shhaa.config.ConfigContextListener</listener-class> </listener 18 --> 10 19 11 20 <servlet> 12 <servlet-name> Jersey Web Application</servlet-name>21 <servlet-name>ComponentRegistry Web Application</servlet-name> 13 22 <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 14 23 <init-param> … … 19 28 </servlet> 20 29 <servlet-mapping> 21 <servlet-name> Jersey Web Application</servlet-name>30 <servlet-name>ComponentRegistry Web Application</servlet-name> 22 31 <url-pattern>/rest/*</url-pattern> 23 32 </servlet-mapping> 24 33 25 34 <security-constraint> 35 <display-name>ComponentRegistry web service</display-name> 36 <web-resource-collection> 37 <web-resource-name>ComponentRegistry edit</web-resource-name> 38 <description></description> 39 <url-pattern>/rest/*</url-pattern> 40 <http-method>DELETE</http-method> 41 <http-method>PUT</http-method> 42 <http-method>POST</http-method> 43 <!-- <http-method>GET</http-method>--> 44 </web-resource-collection> 45 <auth-constraint> 46 <role-name>tomcat</role-name> 47 </auth-constraint> 48 </security-constraint> 49 <login-config> 50 <auth-method>BASIC</auth-method> 51 </login-config> 52 <security-role> 53 <description> 54 The role that is required to log in to the Manager Application 55 </description> 56 <role-name>tomcat</role-name> 57 </security-role> 26 58 </web-app> -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/ComponentRegistryImplTest.java
r136 r207 1 1 package clarin.cmdi.componentregistry; 2 2 3 import static org.junit.Assert.assertEquals;3 import static junit.framework.Assert.assertEquals; 4 4 import static org.junit.Assert.assertFalse; 5 5 import static org.junit.Assert.assertNotNull; 6 6 import static org.junit.Assert.assertNull; 7 7 import static org.junit.Assert.assertTrue; 8 import static org.junit.Assert.fail; 8 9 9 10 import java.io.File; … … 20 21 import clarin.cmdi.componentregistry.model.ComponentDescription; 21 22 import clarin.cmdi.componentregistry.model.ProfileDescription; 23 import clarin.cmdi.componentregistry.rest.DummyPrincipal; 22 24 import clarin.cmdi.componentregistry.rest.TestHelper; 23 25 … … 25 27 26 28 private File tmpRegistryDir; 29 private final static DummyPrincipal PRINCIPAL = DummyPrincipal.DUMMY_PRINCIPAL; 27 30 28 31 @Test … … 262 265 } 263 266 267 @Test 268 public void testDeleteProfile() throws Exception { 269 ComponentRegistry register = getTestRegistry(getRegistryDir()); 270 ProfileDescription description = ProfileDescription.createNewDescription(); 271 description.setName("Aap"); 272 description.setCreatorName(PRINCIPAL.getName()); 273 description.setDescription("MyDescription"); 274 CMDComponentSpec testProfile = TestHelper.getTestProfile(); 275 276 register.registerMDProfile(description, testProfile); 277 278 assertEquals(1, register.getProfileDescriptions().size()); 279 assertNotNull(register.getMDProfile(description.getId())); 280 281 try { 282 register.deleteMDProfile(description.getId(), new DummyPrincipal("Fake User")); 283 fail("Should have thrown exception"); 284 }catch(UserUnauthorizedException e) {} 285 register.deleteMDComponent(description.getId(), new DummyPrincipal("Fake User")); 286 287 assertEquals(1, register.getProfileDescriptions().size()); 288 assertNotNull(register.getMDProfile(description.getId())); 289 290 register.deleteMDProfile(description.getId(), PRINCIPAL); 291 292 assertEquals(0, register.getProfileDescriptions().size()); 293 assertNull(register.getMDProfile(description.getId())); 294 } 295 296 @Test 297 public void testDeleteComponent() throws Exception { 298 ComponentRegistry register = getTestRegistry(getRegistryDir()); 299 ComponentDescription description = ComponentDescription.createNewDescription(); 300 description.setName("Aap"); 301 description.setCreatorName(PRINCIPAL.getName()); 302 description.setDescription("MyDescription"); 303 CMDComponentSpec testProfile = TestHelper.getTestProfile(); 304 305 register.registerMDComponent(description, testProfile); 306 try { 307 register.deleteMDComponent(description.getId(), new DummyPrincipal("Fake User")); 308 fail("Should have thrown exception"); 309 }catch(UserUnauthorizedException e) {} 310 311 assertEquals(1, register.getComponentDescriptions().size()); 312 assertNotNull(register.getMDComponent(description.getId())); 313 314 register.deleteMDComponent(description.getId(), PRINCIPAL); 315 316 assertEquals(0, register.getComponentDescriptions().size()); 317 assertNull(register.getMDProfile(description.getId())); 318 319 } 320 264 321 private File getRegistryDir() { 265 322 if (tmpRegistryDir == null) -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r130 r207 12 12 import java.util.List; 13 13 14 import javax.ws.rs.core.HttpHeaders; 14 15 import javax.ws.rs.core.MediaType; 15 16 import javax.xml.bind.JAXBException; 16 17 17 import org.junit.After Class;18 import org.junit.Before Class;18 import org.junit.After; 19 import org.junit.Before; 19 20 import org.junit.Test; 20 21 … … 26 27 import clarin.cmdi.componentregistry.model.RegisterResponse; 27 28 29 import com.sun.jersey.api.client.ClientResponse; 28 30 import com.sun.jersey.api.client.GenericType; 29 31 import com.sun.jersey.api.client.UniformInterfaceException; 32 import com.sun.jersey.api.client.WebResource; 33 import com.sun.jersey.api.client.WebResource.Builder; 34 import com.sun.jersey.api.core.ResourceConfig; 35 import com.sun.jersey.core.util.Base64; 30 36 import com.sun.jersey.multipart.FormDataMultiPart; 31 37 import com.sun.jersey.test.framework.AppDescriptor; … … 33 39 import com.sun.jersey.test.framework.LowLevelAppDescriptor; 34 40 import com.sun.jersey.test.framework.spi.container.TestContainerFactory; 35 import com.sun.jersey.test.framework.spi.container. inmemory.InMemoryTestContainerFactory;41 import com.sun.jersey.test.framework.spi.container.http.HTTPContainerFactory; 36 42 37 43 public class ComponentRegistryRestServiceTest extends JerseyTest { … … 49 55 @Override 50 56 protected TestContainerFactory getTestContainerFactory() { 51 return new InMemoryTestContainerFactory();57 return new HTTPContainerFactory(); 52 58 } 53 59 54 60 @Override 55 61 protected AppDescriptor configure() { 56 String packageName = ComponentRegistryRestService.class.getPackage().getName(); 57 return new LowLevelAppDescriptor.Builder(packageName).build(); 62 LowLevelAppDescriptor ad = new LowLevelAppDescriptor.Builder(ComponentRegistryRestService.class.getPackage().getName()).build(); 63 ResourceConfig resourceConfig = ad.getResourceConfig(); 64 resourceConfig.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, DummySecurityFilter.class.getName()); 65 return ad; 66 } 67 68 private WebResource getResource() { 69 return resource(); 70 } 71 72 private Builder getAuthenticatedResource(String path) { 73 return getResource().path(path).header(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(DummyPrincipal.DUMMY_PRINCIPAL.getName()+":dummy"))); 58 74 } 59 75 60 76 @Test 61 77 public void testGetRegisteredProfiles() throws Exception { 62 List<ProfileDescription> response = resource().path("/registry/profiles").accept(MediaType.APPLICATION_XML).get(78 List<ProfileDescription> response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_XML).get( 63 79 PROFILE_LIST_GENERICTYPE); 64 80 assertEquals(2, response.size()); 65 response = resource().path("/registry/profiles").accept(MediaType.APPLICATION_JSON).get(PROFILE_LIST_GENERICTYPE);81 response = getResource().path("/registry/profiles").accept(MediaType.APPLICATION_JSON).get(PROFILE_LIST_GENERICTYPE); 66 82 assertEquals(2, response.size()); 67 83 } … … 69 85 @Test 70 86 public void testGetRegisteredComponents() { 71 List<ComponentDescription> response = resource().path("/registry/components").accept(MediaType.APPLICATION_XML).get(87 List<ComponentDescription> response = getResource().path("/registry/components").accept(MediaType.APPLICATION_XML).get( 72 88 COMPONENT_LIST_GENERICTYPE); 73 89 assertEquals(2, response.size()); 74 response = resource().path("/registry/components").accept(MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);90 response = getResource().path("/registry/components").accept(MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE); 75 91 assertEquals(2, response.size()); 76 92 } … … 78 94 @Test 79 95 public void testGetRegisteredComponent() { 80 CMDComponentSpec component = resource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON)96 CMDComponentSpec component = getResource().path("/registry/components/clarin.eu:cr1:component1").accept(MediaType.APPLICATION_JSON) 81 97 .get(CMDComponentSpec.class); 82 98 assertNotNull(component); 83 99 assertEquals("Access", component.getCMDComponent().get(0).getName()); 84 component = resource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get(100 component = getResource().path("/registry/components/clarin.eu:cr1:component2").accept(MediaType.APPLICATION_XML).get( 85 101 CMDComponentSpec.class); 86 102 assertNotNull(component); … … 93 109 94 110 @Test 111 public void testDeleteRegisteredComponent() throws Exception { 112 List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 113 assertEquals(2, components.size()); 114 CMDComponentSpec profile = getResource().path("/registry/components/clarin.eu:cr1:component1").get(CMDComponentSpec.class); 115 assertNotNull(profile); 116 ClientResponse response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class); 117 assertEquals(200, response.getStatus()); 118 119 components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 120 assertEquals(1, components.size()); 121 122 response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component2").delete(ClientResponse.class); 123 assertEquals(200, response.getStatus()); 124 125 components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE); 126 assertEquals(0, components.size()); 127 128 response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").delete(ClientResponse.class); 129 assertEquals(200, response.getStatus()); 130 } 131 132 @Test 95 133 public void testGetRegisteredProfile() throws Exception { 96 CMDComponentSpec profile = resource().path("/registry/profiles/clarin.eu:cr1:profile1").accept(MediaType.APPLICATION_JSON).get(134 CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").accept(MediaType.APPLICATION_JSON).get( 97 135 CMDComponentSpec.class); 98 136 assertNotNull(profile); 99 137 assertEquals("Actor", profile.getCMDComponent().get(0).getName()); 100 profile = resource().path("/registry/profiles/clarin.eu:cr1:profile2").accept(MediaType.APPLICATION_XML)101 .get(CMDComponentSpec.class);138 profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile2").accept(MediaType.APPLICATION_XML).get( 139 CMDComponentSpec.class); 102 140 assertNotNull(profile); 103 141 assertEquals("Actor", profile.getCMDComponent().get(0).getName()); … … 108 146 109 147 try { 110 profile = resource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get(148 profile = getResource().path("/registry/profiles/clarin.eu:cr1:profileXXXX").accept(MediaType.APPLICATION_XML).get( 111 149 CMDComponentSpec.class); 112 150 fail("Exception should have been thrown resouce does not exist, HttpStatusCode 204"); … … 118 156 @Test 119 157 public void testGetRegisteredProfileRawData() throws Exception { 120 String profile = resource().path("/registry/profiles/clarin.eu:cr1:profile1/xsd").accept(MediaType.TEXT_XML).get(String.class);158 String profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xsd").accept(MediaType.TEXT_XML).get(String.class); 121 159 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 122 160 assertTrue(profile.endsWith("</xs:schema>")); 123 161 124 profile = resource().path("/registry/profiles/clarin.eu:cr1:profile1/xml").accept(MediaType.TEXT_XML).get(String.class);162 profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/xml").accept(MediaType.TEXT_XML).get(String.class); 125 163 assertTrue(profile.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 126 164 assertTrue(profile.endsWith("</CMD_ComponentSpec>\n")); 127 165 128 166 try { 129 resource().path("/registry/components/clarin.eu:cr1:component1/xsl").accept(MediaType.TEXT_XML).get(String.class);167 getResource().path("/registry/components/clarin.eu:cr1:component1/xsl").accept(MediaType.TEXT_XML).get(String.class); 130 168 fail("Should have thrown exception, unsopported path parameter"); 131 169 } catch (UniformInterfaceException e) {//server error … … 134 172 135 173 @Test 174 public void testDeleteRegisteredProfile() throws Exception { 175 List<ProfileDescription> profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 176 assertEquals(2, profiles.size()); 177 CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").get(CMDComponentSpec.class); 178 assertNotNull(profile); 179 180 ClientResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class); 181 assertEquals(200, response.getStatus()); 182 183 profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 184 assertEquals(1, profiles.size()); 185 186 response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile2").delete(ClientResponse.class); 187 assertEquals(200, response.getStatus()); 188 189 profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 190 assertEquals(0, profiles.size()); 191 192 response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class); 193 assertEquals(200, response.getStatus()); 194 } 195 196 @Test 136 197 public void testGetRegisteredComponentRawData() throws Exception { 137 String component = resource().path("/registry/components/clarin.eu:cr1:component1/xsd").accept(MediaType.TEXT_XML)138 .get(String.class);198 String component = getResource().path("/registry/components/clarin.eu:cr1:component1/xsd").accept(MediaType.TEXT_XML).get( 199 String.class); 139 200 assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema")); 140 201 assertTrue(component.endsWith("</xs:schema>")); 141 202 142 component = resource().path("/registry/components/clarin.eu:cr1:component1/xml").accept(MediaType.TEXT_XML).get(String.class);203 component = getResource().path("/registry/components/clarin.eu:cr1:component1/xml").accept(MediaType.TEXT_XML).get(String.class); 143 204 assertTrue(component.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); 144 205 assertTrue(component.endsWith("</CMD_ComponentSpec>\n")); 145 206 146 207 try { 147 resource().path("/registry/components/clarin.eu:cr1:component1/jpg").accept(MediaType.TEXT_XML).get(String.class);208 getResource().path("/registry/components/clarin.eu:cr1:component1/jpg").accept(MediaType.TEXT_XML).get(String.class); 148 209 fail("Should have thrown exception, unsopported path parameter"); 149 210 } catch (UniformInterfaceException e) { … … 158 219 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1"); 159 220 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile"); 160 form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit"); 161 RegisterResponse response = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 162 form); 221 RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 222 RegisterResponse.class, form); 163 223 assertTrue(response.isProfile()); 164 224 ProfileDescription profileDesc = (ProfileDescription) response.getDescription(); … … 166 226 assertEquals("ProfileTest1", profileDesc.getName()); 167 227 assertEquals("My Test Profile", profileDesc.getDescription()); 168 assertEquals("J. 228 assertEquals("J.Unit", profileDesc.getCreatorName()); 169 229 assertTrue(profileDesc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_")); 170 230 assertNotNull(profileDesc.getRegistrationDate()); … … 179 239 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ComponentTest1"); 180 240 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Component"); 181 form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit");182 241 form.field(ComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); 183 RegisterResponse response = resource().path("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post(242 RegisterResponse response = getAuthenticatedResource("/registry/components").type(MediaType.MULTIPART_FORM_DATA).post( 184 243 RegisterResponse.class, form); 185 244 assertTrue(response.isRegistered()); … … 189 248 assertEquals("ComponentTest1", desc.getName()); 190 249 assertEquals("My Test Component", desc.getDescription()); 191 assertEquals("J. 250 assertEquals("J.Unit", desc.getCreatorName()); 192 251 assertEquals("TestGroup", desc.getGroupName()); 193 252 assertTrue(desc.getId().startsWith(ComponentRegistry.REGISTRY_ID + "c_")); 194 253 assertNotNull(desc.getRegistrationDate()); 195 String url = resource().getUriBuilder().build().toString();254 String url = getResource().getUriBuilder().build().toString(); 196 255 assertEquals(url + "registry/components/" + desc.getId(), desc.getHref()); 197 256 } … … 205 264 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "ProfileTest1"); 206 265 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test Profile"); 207 form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit"); 208 RegisterResponse postResponse = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 266 RegisterResponse postResponse = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 209 267 RegisterResponse.class, form); 210 268 assertTrue(postResponse.isProfile()); … … 233 291 form.field("name", "");//Empty name so invalid 234 292 form.field("description", "My Test Profile"); 235 form.field("creatorName", "J. Unit"); 236 RegisterResponse response = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 237 form); 293 RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 294 RegisterResponse.class, form); 238 295 assertFalse(response.isRegistered()); 239 296 assertEquals(2, response.getErrors().size()); … … 249 306 form.field(ComponentRegistryRestService.NAME_FORM_FIELD, "t"); 250 307 form.field(ComponentRegistryRestService.DESCRIPTION_FORM_FIELD, "My Test"); 251 form.field(ComponentRegistryRestService.CREATOR_NAME_FORM_FIELD, "J. Unit"); 252 RegisterResponse response = resource().path("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 253 form); 308 RegisterResponse response = getAuthenticatedResource("/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( 309 RegisterResponse.class, form); 254 310 assertFalse(response.isRegistered()); 255 311 assertTrue(response.isProfile()); … … 258 314 } 259 315 260 @Before Class261 public staticvoid setUpTestRegistry() throws ParseException, JAXBException {316 @Before 317 public void setUpTestRegistry() throws ParseException, JAXBException { 262 318 registryDir = ComponentRegistryImplTest.createTempRegistryDir(); 263 319 testRegistry = ComponentRegistryImplTest.getTestRegistry(registryDir); … … 268 324 } 269 325 270 @After Class271 public static void deleteRegistry() {326 @After 327 public void deleteAndRecreateEmptyRegistry() { 272 328 ComponentRegistryImplTest.cleanUpRegistryDir(registryDir); 273 274 329 } 275 330 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/TestHelper.java
r136 r207 28 28 } 29 29 30 public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException, JAXBException { 30 public static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, String content) throws ParseException, 31 JAXBException { 31 32 return addComponent(testRegistry, id, new ByteArrayInputStream(content.getBytes())); 32 33 } 33 34 34 35 private static ComponentDescription addComponent(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException, 35 36 JAXBException { 36 37 ComponentDescription desc = ComponentDescription.createNewDescription(); 37 desc.setCreatorName( "J. Unit");38 desc.setCreatorName(DummyPrincipal.DUMMY_PRINCIPAL.getName()); 38 39 desc.setName("testComponent"); 39 40 desc.setRegistrationDate("" + SimpleDateFormat.getDateInstance(DateFormat.SHORT).parse("1/1/2009")); … … 81 82 JAXBException { 82 83 ProfileDescription desc = ProfileDescription.createNewDescription(); 83 desc.setCreatorName( "J. Unit");84 desc.setCreatorName(DummyPrincipal.DUMMY_PRINCIPAL.getName()); 84 85 desc.setName("testProfile"); 85 86 desc.setRegistrationDate("" + SimpleDateFormat.getDateInstance(DateFormat.SHORT).parse("1/1/2009"));
Note: See TracChangeset
for help on using the changeset viewer.