Commit 2a1e5786 authored by gmantele's avatar gmantele
Browse files

[UWS,TAP] Review the standard parameters checking. Particularly, because...

[UWS,TAP] Review the standard parameters checking. Particularly, because before, the default value was never used while no value was specified by the user.
parent 425d77e9
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ import adql.query.ADQLQuery;
 * Only the functions related with the database connection stay abstract.
 * 
 * @author Grégory Mantelet (CDS;ARI)
 * @version 2.0 (10/2014)
 * @version 2.0 (11/2014)
 */
public abstract class AbstractTAPFactory extends TAPFactory {

@@ -277,7 +277,7 @@ public abstract class AbstractTAPFactory extends TAPFactory {
	@Override
	public TAPParameters createTAPParameters(final HttpServletRequest request) throws TAPException{
		try{
			return new TAPParameters(request, service, getExpectedAdditionalParameters(), getInputParamControllers());
			return new TAPParameters(request, service);
		}catch(UWSException ue){
			throw new TAPException(ue);
		}
@@ -296,7 +296,7 @@ public abstract class AbstractTAPFactory extends TAPFactory {
	@Override
	public TAPParameters createTAPParameters(final Map<String,Object> params) throws TAPException{
		try{
			return new TAPParameters(service, params, getExpectedAdditionalParameters(), getInputParamControllers());
			return new TAPParameters(service, params);
		}catch(UWSException ue){
			throw new TAPException(ue);
		}
+3 −3
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import uws.job.Result;
import uws.job.UWSJob;
import uws.job.parameters.UWSParameters;
import uws.job.user.JobOwner;
import uws.service.AbstractUWSFactory;
import uws.service.UWSFactory;
import uws.service.UWSService;
import uws.service.backup.UWSBackupManager;
import uws.service.error.ServiceErrorWriter;
@@ -59,9 +59,9 @@ import adql.query.ADQLQuery;
 * </ul>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (09/2014)
 * @version 2.0 (11/2014)
 */
public abstract class TAPFactory extends AbstractUWSFactory {
public abstract class TAPFactory implements UWSFactory {

	/** Connection to the TAP service ; it provides all important service configuration information. */
	protected final ServiceConnection service;
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ public class FormatController implements InputParamController {
	@Override
	public Object check(Object format) throws UWSException{
		if (format == null)
			return null;
			return getDefault();

		if (format instanceof String){
			String strFormat = ((String)format).trim();
+23 −11
Original line number Diff line number Diff line
@@ -32,17 +32,24 @@ import uws.job.parameters.InputParamController;
 * 
 * <p><i>Note:
 * 	By default, this parameter can be modified by anyone without any limitation.
 * 	The default and maximum value is set by default to {@link TAPJob#UNLIMITED_MAX_REC}.
 * </i></p>
 * 
 * <p><i>Note:
 * 	The special value 0 means that just the metadata of the result must be returned.
 * 	Considering the meaning of this value, it will not be considered as an {@link TAPJob#UNLIMITED_MAX_REC},
 * 	but like a valid value. The maximum value can then be also 0.
 * </i></p>
 * 
 * <p>The logic of the output limit is set in this class. Here it is:</p>
 * <ul>
 * 	<li>If no value is specified by the TAP client, none is returned.</li>
 *  <li>If no default value is provided, no default limitation is set (={@link TAPJob#UNLIMITED_MAX_REC}).</li>
 *  <li>If no maximum value is provided, there is no output limit (={@link TAPJob#UNLIMITED_MAX_REC}).</li>
 * 	<li>If no value is specified by the TAP client, the default value is returned.</li>
 *  <li>If no default value is provided, the maximum output limit is returned.</li>
 *  <li>If no maximum value is provided, there is no limit (={@link TAPJob#UNLIMITED_MAX_REC}).</li>
 * </ul>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (09/2014)
 * @version 2.0 (11/2014)
 */
public class MaxRecController implements InputParamController {

@@ -63,13 +70,18 @@ public class MaxRecController implements InputParamController {

	@Override
	public final Object getDefault(){
		// If a default output limit is set by the TAP service connection, return it:
		// Get the default output limit:
		int defaultLimit = TAPJob.UNLIMITED_MAX_REC;
		if (service.getOutputLimit() != null && service.getOutputLimit().length >= 2 && service.getOutputLimitType() != null && service.getOutputLimitType().length == service.getOutputLimit().length){
			if (service.getOutputLimit()[0] > 0 && service.getOutputLimitType()[0] == LimitUnit.rows)
				return service.getOutputLimit()[0];
				defaultLimit = service.getOutputLimit()[0];
		}
		// Otherwise, return no limitation:
		return TAPJob.UNLIMITED_MAX_REC;

		// Get the maximum output limit, for comparison:
		int maxLimit = getMaxOutputLimit();

		// Ensure the default limit is less or equal the maximum limit:
		return (defaultLimit < 0 || (maxLimit >= 0 && defaultLimit > maxLimit)) ? maxLimit : defaultLimit;
	}

	/**
@@ -91,7 +103,7 @@ public class MaxRecController implements InputParamController {
	public Object check(Object value) throws UWSException{
		// If no limit is provided by the TAP client, none is returned:
		if (value == null)
			return null;
			return getDefault();

		// Parse the provided limit:
		int maxOutputLimit = getMaxOutputLimit();
@@ -109,11 +121,11 @@ public class MaxRecController implements InputParamController {
			throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter \"maxrec\": class \"" + value.getClass().getName() + "\"! It should be an integer or a string containing only an integer value.");

		// A negative output limit is considered as an unlimited output limit:
		if (maxRec < TAPJob.UNLIMITED_MAX_REC)
		if (maxRec < 0)
			maxRec = TAPJob.UNLIMITED_MAX_REC;

		// If the limit is greater than the maximum one, an exception is thrown:
		if (maxRec == TAPJob.UNLIMITED_MAX_REC || maxRec > maxOutputLimit)
		if (maxRec < 0 || (maxOutputLimit >= 0 && maxRec > maxOutputLimit))
			maxRec = maxOutputLimit;

		return maxRec;
+33 −14
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import java.util.Date;
import tap.ServiceConnection;
import uws.ISO8601Format;
import uws.UWSException;
import uws.job.UWSJob;
import uws.job.parameters.DestructionTimeController.DateField;
import uws.job.parameters.InputParamController;

@@ -40,8 +39,15 @@ import uws.job.parameters.InputParamController;
 * 	There is no default value (that means jobs may stay forever).
 * </i></p>
 * 
 * <p>The logic of the destruction time is set in this class. Here it is:</p>
 * <ul>
 * 	<li>If no value is specified by the UWS client, the default value is returned.</li>
 *  <li>If no default value is provided, the maximum destruction date is returned.</li>
 *  <li>If no maximum value is provided, there is no destruction.</li>
 * </ul>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (09/2014)
 * @version 2.0 (11/2014)
 */
public class TAPDestructionTimeController implements InputParamController {

@@ -90,17 +96,23 @@ public class TAPDestructionTimeController implements InputParamController {

	@Override
	public final Object getDefault(){
		// Get the default period and ensure it is always less or equal the maximum period, if any:
		int defaultPeriod = getDefaultRetentionPeriod();
		int maxPeriod = getMaxRetentionPeriod();
		if (defaultPeriod <= 0 || (maxPeriod > 0 && defaultPeriod > maxPeriod))
			defaultPeriod = maxPeriod;

		// Build and return the date:
		if (defaultPeriod > 0){
			Calendar date = Calendar.getInstance();
			try{
				date.add(DateField.SECOND.getFieldIndex(), defaultPeriod);
				return date.getTime();
			}catch(ArrayIndexOutOfBoundsException ex){
				return null;
			}catch(ArrayIndexOutOfBoundsException ex){}
		}
		}else
			return null;

		// If no default period is specified or if an exception occurs, the maximum destruction time must be returned:
		return getMaxDestructionTime();
	}

	/**
@@ -123,24 +135,29 @@ public class TAPDestructionTimeController implements InputParamController {
	 * @return The maximum destruction time (<i>null</i> means that jobs may stay forever).
	 */
	public final Date getMaxDestructionTime(){
		// Get the maximum period:
		int maxPeriod = getMaxRetentionPeriod();

		// Build and return the maximum destruction date:
		if (maxPeriod > 0){
			Calendar date = Calendar.getInstance();
			try{
				date.add(DateField.SECOND.getFieldIndex(), maxPeriod);
				return date.getTime();
			}catch(ArrayIndexOutOfBoundsException ex){
				return null;
			}catch(ArrayIndexOutOfBoundsException ex){}
		}
		}else

		// If no maximum period is specified or if an exception occurs, NULL must be returned:
		return null;
	}

	@Override
	public Object check(Object value) throws UWSException{
		// If NULL value, return the default value:
		if (value == null)
			return null;
			return getDefault();

		// Parse the given date:
		Date date = null;
		if (value instanceof Date)
			date = (Date)value;
@@ -154,10 +171,12 @@ public class TAPDestructionTimeController implements InputParamController {
		}else
			throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Wrong type for the parameter \"destruction\": class \"" + value.getClass().getName() + "\"! It should be a Date or a string containing a date formatted in ISO8601 (\"yyyy-MM-dd'T'hh:mm:ss[.sss]['Z'|[+|-]hh:mm]\", fields inside brackets are optional).");

		// Ensure the date is before the maximum destruction time (from now):
		Date maxDate = getMaxDestructionTime();
		if (maxDate != null && date.after(maxDate))
			throw new UWSException(UWSException.BAD_REQUEST, "The TAP service limits the destruction interval (since now) to " + getMaxRetentionPeriod() + " s !");
			date = maxDate;

		// Return the parsed date
		return date;
	}

Loading