Unverified Commit 1c3cb75b authored by Fabien Viale's avatar Fabien Viale Committed by GitHub
Browse files

Merge pull request #19 from ow2-proactive/master

synchronize fork
parents 10d828e1 2c18b2b2
......@@ -106,7 +106,7 @@ public interface RestDataspace {
* <li>If the pathname represents a file, its contents will be returned as:
* <ul>
* <li>an octet stream, if its a compressed file already or if the client doesn't
* accept encoded content</li>
* accept encoded content (encoding specified as "identity")</li>
* <li>a 'gzip' encoded stream, if the client accepts 'gzip' encoded content
* </li>
* <li>a 'zip' encoded stream, if the client accepts 'zip' encoded contents</li>
......@@ -119,21 +119,23 @@ public interface RestDataspace {
* returned from the specified location.</li>
* </ul>
* @param sessionId a valid session id
* @param headerAcceptEncoding the accepted encoding supported by the client, can be "*", "gzip", "zip", "identity" or empty. When the query parameter {@code encoding} is specified, it is overridden by {@code encoding}.
* @param dataspace can have two possible values, 'user' or 'global',
* depending on the target <i>DATASPACE</i>
* @param pathname location of the file or folder to retrieve
* @param component can either be 'list' or empty. If 'list' is used, the response will contain in JSON format the list of files and folder presents at specified location, equivalent to a directory listing.
* @param encoding accepted encoding supported by the client, can be "*", "gzip", "zip" or empty.
* @param includes a list of inclusion directives
* @param excludes a list of exclusion directives
* @param encoding the accepted encoding supported by the client, can be "*", "gzip", "zip", "identity" or empty. It overrides the accepted encoding specified in {@code headerAcceptEncoding}.
* @return a REST response which can have various content-types
*/
@GET
@Path("/{dataspace}/{path-name:.*}")
Response retrieve(@HeaderParam("sessionid") String sessionId, @HeaderParam("Accept-Encoding") String encoding,
@PathParam("dataspace") String dataspace, @PathParam("path-name") String pathname,
@QueryParam("comp") String component, @QueryParam("includes") List<String> includes,
@QueryParam("excludes") List<String> excludes) throws NotConnectedRestException, PermissionRestException;
Response retrieve(@HeaderParam("sessionid") String sessionId,
@HeaderParam("Accept-Encoding") String headerAcceptEncoding, @PathParam("dataspace") String dataspace,
@PathParam("path-name") String pathname, @QueryParam("comp") String component,
@QueryParam("includes") List<String> includes, @QueryParam("excludes") List<String> excludes,
@QueryParam("encoding") String encoding) throws NotConnectedRestException, PermissionRestException;
/**
* Delete file(s) from the specified location in the <i>dataspace</i>.
......
......@@ -92,10 +92,17 @@ public class RestDataspaceImpl implements RestDataspace {
@Override
public Response retrieve(@HeaderParam("sessionid") String sessionId,
@HeaderParam("Accept-Encoding") String encoding, @PathParam("dataspace") String dataspace,
@HeaderParam("Accept-Encoding") String headerAcceptEncoding, @PathParam("dataspace") String dataspace,
@PathParam("path-name") String pathname, @QueryParam("comp") String component,
@QueryParam("includes") List<String> includes, @QueryParam("excludes") List<String> excludes)
throws NotConnectedRestException, PermissionRestException {
@QueryParam("includes") List<String> includes, @QueryParam("excludes") List<String> excludes,
@QueryParam("encoding") String encoding) throws NotConnectedRestException, PermissionRestException {
if (encoding == null) {
encoding = headerAcceptEncoding;
}
logger.debug(String.format("Retrieving file %s in %s with encoding %s",
pathname,
dataspace.toUpperCase(),
encoding));
Session session = checkSessionValidity(sessionId);
try {
checkPathParams(dataspace, pathname);
......
......@@ -38,6 +38,10 @@ public class GlobalFileParserValidator extends BaseParserValidator<String> {
super(model, ModelType.GLOBAL_FILE);
}
public GlobalFileParserValidator(String model, ModelType type) throws ModelSyntaxException {
super(model, type);
}
@Override
protected Converter<String> createConverter(String model) throws ModelSyntaxException {
return new IdentityConverter();
......
......@@ -25,8 +25,6 @@
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import java.net.URI;
import java.net.URL;
import java.util.Date;
......@@ -50,12 +48,16 @@ public enum ModelType {
REGEXP(RegexpParserValidator.class, String.class),
SHORT(ShortParserValidator.class, Short.class),
SPEL(SPELParserValidator.class, String.class),
URI(URIParserValidator.class, URI.class),
URL(URLParserValidator.class, URL.class),
URI(URIParserValidator.class, String.class),
OPTIONAL_URI(OptionalURIParserValidator.class, String.class),
URL(URLParserValidator.class, String.class),
OPTIONAL_URL(OptionalURLParserValidator.class, String.class),
HIDDEN(HiddenParserValidator.class, String.class),
CREDENTIAL(CredentialParserValidator.class, String.class),
USER_FILE(UserFileParserValidator.class, URI.class),
GLOBAL_FILE(GlobalFileParserValidator.class, URI.class);
USER_FILE(UserFileParserValidator.class, String.class),
OPTIONAL_USER_FILE(OptionalUserFileParserValidator.class, String.class),
GLOBAL_FILE(GlobalFileParserValidator.class, String.class),
OPTIONAL_GLOBAL_FILE(OptionalGlobalFileParserValidator.class, String.class);
// The parser validator of the model type
private Class typeParserValidator;
......
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.GlobalFileValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class OptionalGlobalFileParserValidator extends GlobalFileParserValidator {
public OptionalGlobalFileParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.OPTIONAL_GLOBAL_FILE);
}
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new OptionalValidator<>(new GlobalFileValidator());
}
}
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.URIValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class OptionalURIParserValidator extends URIParserValidator {
public OptionalURIParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.OPTIONAL_URI);
}
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new OptionalValidator<>(new URIValidator());
}
}
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.URLValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class OptionalURLParserValidator extends URLParserValidator {
public OptionalURLParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.OPTIONAL_URL);
}
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new OptionalValidator<>(new URLValidator());
}
}
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.UserFileValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class OptionalUserFileParserValidator extends UserFileParserValidator {
public OptionalUserFileParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.OPTIONAL_USER_FILE);
}
@Override
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new OptionalValidator<>(new UserFileValidator());
}
}
......@@ -25,28 +25,30 @@
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import java.net.URI;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.URIConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.IdentityConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.AcceptAllValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.URIValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class URIParserValidator extends BaseParserValidator<URI> {
public class URIParserValidator extends BaseParserValidator<String> {
public URIParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.URI);
}
public URIParserValidator(String model, ModelType type) throws ModelSyntaxException {
super(model, type);
}
@Override
protected Converter<URI> createConverter(String model) throws ModelSyntaxException {
return new URIConverter();
protected Converter<String> createConverter(String model) throws ModelSyntaxException {
return new IdentityConverter();
}
@Override
protected Validator<URI> createValidator(String model, Converter<URI> converter) throws ModelSyntaxException {
return new AcceptAllValidator<>();
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new URIValidator();
}
}
......@@ -25,28 +25,30 @@
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import java.net.URL;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.URLConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.IdentityConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.AcceptAllValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.URLValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class URLParserValidator extends BaseParserValidator<URL> {
public class URLParserValidator extends BaseParserValidator<String> {
public URLParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.URL);
}
public URLParserValidator(String model, ModelType type) throws ModelSyntaxException {
super(model, type);
}
@Override
protected Converter<URL> createConverter(String model) throws ModelSyntaxException {
return new URLConverter();
protected Converter<String> createConverter(String model) throws ModelSyntaxException {
return new IdentityConverter();
}
@Override
protected Validator<URL> createValidator(String model, Converter<URL> converter) throws ModelSyntaxException {
return new AcceptAllValidator<>();
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new URLValidator();
}
}
......@@ -38,6 +38,10 @@ public class UserFileParserValidator extends BaseParserValidator<String> {
super(model, ModelType.USER_FILE);
}
public UserFileParserValidator(String model, ModelType type) throws ModelSyntaxException {
super(model, type);
}
@Override
protected Converter<String> createConverter(String model) throws ModelSyntaxException {
return new IdentityConverter();
......
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.validator;
import org.apache.commons.lang3.StringUtils;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException;
/**
* Validate all the blank parameter value. When the value is not blank, use its specific validator to check the value validity.
* @param <T>
*/
public class OptionalValidator<T> implements Validator<T> {
Validator<T> validator;
public OptionalValidator(Validator<T> validator) {
this.validator = validator;
}
@Override
public T validate(T parameterValue, ModelValidatorContext context) throws ValidationException {
// When the parameter value is not provided, it's validated. Otherwise, use its proper validator
if (StringUtils.isBlank(parameterValue.toString())) {
return parameterValue;
} else {
return validator.validate(parameterValue, context);
}
}
}
......@@ -23,21 +23,27 @@
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.converter;
package org.ow2.proactive.scheduler.common.job.factories.spi.model.validator;
import java.net.URI;
import java.net.URISyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ConversionException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException;
public class URIConverter implements Converter<URI> {
/**
* @author ActiveEon Team
* @since 19/08/19s
*/
public class URIValidator implements Validator<String> {
@Override
public URI convert(String parameterValue) throws ConversionException {
public String validate(String parameterValue, ModelValidatorContext context) throws ValidationException {
try {
return new URI(parameterValue);
return new URI(parameterValue).toString();
} catch (URISyntaxException e) {
throw new ConversionException(parameterValue, URI.class, e.getMessage(), e);
throw new ValidationException(parameterValue + " is not a valid URI.", e);
}
}
}
......@@ -23,21 +23,27 @@
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.converter;
package org.ow2.proactive.scheduler.common.job.factories.spi.model.validator;
import java.net.MalformedURLException;
import java.net.URL;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ConversionException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException;
public class URLConverter implements Converter<URL> {
/**
* @author ActiveEon Team
* @since 19/08/19s
*/
public class URLValidator implements Validator<String> {
@Override
public URL convert(String parameterValue) throws ConversionException {
public String validate(String parameterValue, ModelValidatorContext context) throws ValidationException {
try {
return new URL(parameterValue);
return new URL(parameterValue).toString();
} catch (MalformedURLException e) {
throw new ConversionException(parameterValue, URL.class, e.getMessage(), e);
throw new ValidationException(parameterValue + " is not a valid URL.", e);
}
}
}
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import static org.mockito.Mockito.when;
import static org.ow2.proactive.scheduler.common.SchedulerConstants.GLOBALSPACE_NAME;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;