ValidationException
This commit is contained in:
parent
0e97f9739b
commit
76c0de232c
|
@ -3,10 +3,9 @@ package org.gcube.application.geoportal.managers;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
import javax.xml.bind.ValidationException;
|
||||
|
||||
import org.gcube.application.geoportal.model.Record;
|
||||
import org.gcube.application.geoportal.model.ValidationReport;
|
||||
import org.gcube.application.geoportal.model.content.AssociatedContent;
|
||||
import org.gcube.application.geoportal.model.db.DBConstants;
|
||||
import org.gcube.application.geoportal.model.fault.PersistenceException;
|
||||
import org.gcube.application.geoportal.storage.ContentHandler;
|
||||
|
@ -68,7 +67,7 @@ public abstract class AbstractRecordManager<T extends Record> {
|
|||
return theRecord;
|
||||
};
|
||||
|
||||
public abstract ValidationReport validate();
|
||||
public abstract void validate() throws ValidationException;
|
||||
|
||||
/**
|
||||
* Commit to storages
|
||||
|
@ -76,15 +75,23 @@ public abstract class AbstractRecordManager<T extends Record> {
|
|||
* @return
|
||||
* @throws PersistenceException
|
||||
*/
|
||||
public T commit(boolean publish) throws PersistenceException {
|
||||
public T commit(boolean publish) throws PersistenceException,ValidationException {
|
||||
|
||||
if (publish) validate();
|
||||
// storeInfo(theRecord);
|
||||
contentHandler.persist(publish);
|
||||
log.debug("Storing content of "+theRecord);
|
||||
contentHandler.storeChanges();
|
||||
if(publish) {
|
||||
log.debug("Publishing content of "+theRecord);
|
||||
publish();
|
||||
}
|
||||
log.debug("Updating register with "+theRecord);
|
||||
storeInfo(theRecord);
|
||||
return theRecord;
|
||||
}
|
||||
|
||||
protected abstract void publish();
|
||||
|
||||
/**
|
||||
* Updates info related to current project
|
||||
* @param updatedInfo
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package org.gcube.application.geoportal.managers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.bind.ValidationException;
|
||||
|
||||
import org.gcube.application.geoportal.model.InputStreamDescriptor;
|
||||
import org.gcube.application.geoportal.model.ValidationReport;
|
||||
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
||||
import org.gcube.application.geoportal.model.concessioni.LayerConcessione;
|
||||
import org.gcube.application.geoportal.model.concessioni.RelazioneScavo;
|
||||
|
@ -77,9 +77,15 @@ public class ConcessioneManager extends AbstractRecordManager<Concessione> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ValidationReport validate() {
|
||||
public void validate() throws ValidationException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void publish() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package org.gcube.application.geoportal.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ValidationReport {
|
||||
|
||||
public ValidationReport() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
private List<String> message;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package org.gcube.application.geoportal.model.fault;
|
||||
|
||||
import org.gcube.application.geoportal.model.ValidationReport;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ValidationException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6614557911302878653L;
|
||||
private ValidationReport report;
|
||||
public ValidationException(ValidationReport report) {
|
||||
super();
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
public ValidationException(ValidationReport report, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
this.report = report;
|
||||
}
|
||||
public ValidationException(ValidationReport report, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.report = report;
|
||||
}
|
||||
public ValidationException(ValidationReport report, String message) {
|
||||
super(message);
|
||||
this.report = report;
|
||||
}
|
||||
public ValidationException(ValidationReport report, Throwable cause) {
|
||||
super(cause);
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -93,7 +93,7 @@ public class ContentHandler {
|
|||
|
||||
}
|
||||
|
||||
public void persist(boolean publish) throws PersistenceException {
|
||||
public void storeChanges() throws PersistenceException {
|
||||
|
||||
//
|
||||
|
||||
|
@ -146,10 +146,8 @@ public class ContentHandler {
|
|||
|
||||
}
|
||||
|
||||
//************* WS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.application.geoportal;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.ValidationException;
|
||||
|
||||
import org.gcube.application.geoportal.managers.ConcessioneManager;
|
||||
import org.gcube.application.geoportal.managers.ManagerFactory;
|
||||
import org.gcube.application.geoportal.model.InputStreamDescriptor;
|
||||
|
@ -17,13 +19,13 @@ import org.junit.Assert;
|
|||
|
||||
public class UseCases {
|
||||
|
||||
public static void main(String[] args) throws PersistenceException, IOException {
|
||||
public static void main(String[] args) throws PersistenceException, IOException, ValidationException {
|
||||
TokenSetter.set("/gcube/devNext/NextNext");
|
||||
registerNewConcessione();
|
||||
}
|
||||
|
||||
|
||||
public static void registerNewConcessione() throws PersistenceException, IOException {
|
||||
public static void registerNewConcessione() throws PersistenceException, IOException, ValidationException {
|
||||
|
||||
//Preparo l'istanza del modello con i vari campi compilati e senza gli allegati
|
||||
Concessione conc=TestModel.prepareEmptyConcessione();
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.application.geoportal.db;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.xml.bind.ValidationException;
|
||||
|
||||
import org.gcube.application.geoportal.TestModel;
|
||||
import org.gcube.application.geoportal.managers.ConcessioneManager;
|
||||
import org.gcube.application.geoportal.managers.ManagerFactory;
|
||||
|
@ -14,7 +16,7 @@ public class Records {
|
|||
|
||||
|
||||
@Test
|
||||
public void Concessioni() throws PersistenceException {
|
||||
public void Concessioni() throws PersistenceException, ValidationException {
|
||||
Concessione conc=TestModel.prepareConcessione();
|
||||
ConcessioneManager manager=ManagerFactory.registerNew(conc);
|
||||
String updatedString="Definitely a new name for this thing";
|
||||
|
|
Loading…
Reference in New Issue