File registration request validation
This commit is contained in:
parent
c81861c3e5
commit
fe3239a1bc
|
@ -150,6 +150,7 @@ public class DefaultMongoConcessioni implements MongoConcessioni{
|
|||
@Override
|
||||
public Concessione registerFileSet(String id, AddSectionToConcessioneRequest request) throws Exception {
|
||||
log.info("Registering {} in {}",request,id);
|
||||
request.validate();
|
||||
Call<WebTarget,Concessione> call= endpoint -> {
|
||||
Response resp= endpoint.path(InterfaceConstants.Methods.REGISTER_FILES_PATH).
|
||||
path(id).request(MediaType.APPLICATION_JSON).post(Entity.entity(mapper.writeValueAsString(request),
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.geoportal.common.faults;
|
||||
|
||||
public class InvalidRequestException extends Exception{
|
||||
public InvalidRequestException() {
|
||||
}
|
||||
|
||||
public InvalidRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidRequestException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidRequestException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidRequestException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
import org.gcube.application.geoportal.common.model.legacy.report.Check;
|
||||
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
|
||||
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
|
||||
|
@ -107,6 +108,23 @@ public class Concessione extends Record{
|
|||
private static String makeByIndex(String base,int value) {return String.format("%1$s[%2$d]",base,value);}
|
||||
private static String makeByStringField(String base,String field,String value)
|
||||
{return String.format("%1$s.%2$s:\"%3$s\"",base,field,value);}
|
||||
|
||||
public static boolean validate(String path) throws InvalidRequestException {
|
||||
switch(path) {
|
||||
case Paths.RELAZIONE :
|
||||
case Paths.POSIZIONAMENTO :
|
||||
case Paths.ABSTRACT_RELAZIONE: return true;
|
||||
}
|
||||
if(path.matches("\\w+\\[\\d+\\]")) {
|
||||
// Array section
|
||||
return true;
|
||||
}
|
||||
if(path.matches("\\w+\\.\\w+\\s*\\:\\s*\\\"\\w+\\\"")) {
|
||||
// Map section
|
||||
return true;
|
||||
}
|
||||
throw new InvalidRequestException("Invalid Path "+path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,8 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.gcube.application.geoportal.common.rest.TempFile;
|
||||
|
||||
@XmlRootElement
|
||||
|
@ -17,5 +19,11 @@ public class AddSectionToConcessioneRequest {
|
|||
|
||||
private String destinationPath;
|
||||
private List<TempFile> streams;
|
||||
|
||||
|
||||
|
||||
public void validate()throws InvalidRequestException {
|
||||
Concessione.Paths.validate(destinationPath);
|
||||
if(streams==null || streams.isEmpty()) throw new InvalidRequestException("No Temp File declared");
|
||||
for(TempFile t : streams) t.validate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.application.geoportal.common.rest;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
@ -11,5 +12,9 @@ public class TempFile {
|
|||
|
||||
private String id;
|
||||
private String filename;
|
||||
|
||||
|
||||
public void validate()throws InvalidRequestException {
|
||||
if(id==null || id.isEmpty()) throw new InvalidRequestException("Invalid temp file "+this+" : ID null or empty");
|
||||
if(filename==null || filename.isEmpty()) throw new InvalidRequestException("Invalid temp file "+this+" : filename null or empty");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,8 +81,6 @@ public class ConcessioniOverMongo {
|
|||
|
||||
};
|
||||
}.execute().getResult();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,6 +175,7 @@ public class ConcessioniOverMongo {
|
|||
log.info("Registering {} file(s) for {} Concessione ID {}",
|
||||
request.getStreams().size(),
|
||||
request.getDestinationPath(),id);
|
||||
request.validate();
|
||||
ConcessioniMongoManager manager=new ConcessioniMongoManager();
|
||||
return manager.persistContent(id, request.getDestinationPath(), request.getStreams());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.application.geoportal.service.engine.caches;
|
||||
|
||||
import com.mongodb.MongoWaitQueueFullException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.service.BasicServiceTestUnit;
|
||||
|
@ -79,8 +80,11 @@ public class Caches extends BasicServiceTestUnit {
|
|||
new ConcessioniMongoManager().list();
|
||||
} catch (ConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MongoWaitQueueFullException e) {
|
||||
log.info("Too many connections... ");
|
||||
}finally{
|
||||
executed.incrementAndGet();
|
||||
try {Thread.sleep(500);} catch (InterruptedException i) {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue