Clear FileSet Feature
This commit is contained in:
parent
b5d72ddd82
commit
ad56a91310
|
@ -201,7 +201,9 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
}
|
||||
|
||||
|
||||
public static Concessione removeContent(Concessione concessione) throws DeletionException {
|
||||
|
||||
|
||||
private static Concessione removeContent(Concessione concessione) throws DeletionException {
|
||||
if(concessione.getFolderId()==null) {
|
||||
log.debug("No content for " + concessione.getMongo_id());
|
||||
return concessione;
|
||||
|
@ -228,6 +230,33 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
|
||||
}
|
||||
|
||||
public Concessione unregisterFileset(String id, String toClearPath) throws Exception {
|
||||
log.info("Clearing Fileset at {} for {} ",toClearPath,id);
|
||||
try {
|
||||
WorkspaceManager ws=new WorkspaceManager();
|
||||
Concessione c = getById(id);
|
||||
AssociatedContent toClearContent=c.getContentByPath(toClearPath);
|
||||
log.debug("Found content {} for path {}",toClearContent,toClearPath);
|
||||
|
||||
//checking if published content
|
||||
for(PersistedContent persisted : toClearContent.getActualContent()){
|
||||
if(persisted instanceof GeoServerContent) throw new Exception ("Cannot clear concessione "+id+" at "+toClearContent+", because it is published.");
|
||||
}
|
||||
|
||||
for(PersistedContent persisted : toClearContent.getActualContent()){
|
||||
if(persisted instanceof WorkspaceContent) ws.deleteFromWS((WorkspaceContent) persisted);
|
||||
}
|
||||
toClearContent.getActualContent().clear();
|
||||
|
||||
log.debug("Updating dafults for {} ",c);
|
||||
c.setDefaults();
|
||||
return asConcessione(replace(asDocument(c),collectionName));
|
||||
|
||||
}catch(Exception e) {
|
||||
throw new Exception("Unable to unregister files.",e);
|
||||
}
|
||||
}
|
||||
|
||||
public Concessione persistContent(String id, String destinationPath, List<TempFile> files) throws Exception{
|
||||
log.info("Persisting {} files for path {} in concessione ",files.size(),destinationPath,id);
|
||||
try{
|
||||
|
|
|
@ -182,6 +182,23 @@ public class ConcessioniOverMongo {
|
|||
}.execute().getResult();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/"+InterfaceConstants.Methods.DELETE_FILES_PATH+"/{"+InterfaceConstants.Parameters.PROJECT_ID+"}")
|
||||
public Concessione clearFileset(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, String path) {
|
||||
return new GuardedMethod<Concessione>() {
|
||||
@Override
|
||||
protected Concessione run() throws Exception, WebApplicationException {
|
||||
log.info("Clearing files of {} Concessione ID {}",path,id);
|
||||
ConcessioniMongoManager manager=new ConcessioniMongoManager();
|
||||
return manager.unregisterFileset(id,path);
|
||||
}
|
||||
}.execute().getResult();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
|
|
@ -231,7 +231,38 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{
|
|||
System.out.println("File is "+c.getRelazioneScavo().getActualContent().get(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testClearFileSet() throws Exception {
|
||||
WebTarget target=target(PATH);
|
||||
Concessione published=getFullPublished(target);
|
||||
|
||||
|
||||
String path=Paths.POSIZIONAMENTO;
|
||||
Response resp=
|
||||
target.path(InterfaceConstants.Methods.DELETE_FILES_PATH).path(published.getMongo_id()).
|
||||
request(MediaType.APPLICATION_JSON).put(Entity.entity(path, MediaType.APPLICATION_JSON));
|
||||
//Expecting error for deletion
|
||||
assertTrue(resp.getStatus()>=300);
|
||||
System.out.println("Error for deletion is "+resp.readEntity(String.class));
|
||||
resp=
|
||||
target.path(InterfaceConstants.Methods.PUBLISH_PATH).path(published.getMongo_id()).
|
||||
request(MediaType.APPLICATION_JSON).delete();
|
||||
check(resp,null);
|
||||
|
||||
//Actually cleaning posizionamento
|
||||
published=check(
|
||||
target.path(InterfaceConstants.Methods.DELETE_FILES_PATH).path(published.getMongo_id()).
|
||||
request(MediaType.APPLICATION_JSON).post(Entity.entity(path, MediaType.APPLICATION_JSON)),Concessione.class);
|
||||
|
||||
assertTrue(published.getPosizionamentoScavo().getActualContent().isEmpty());
|
||||
|
||||
path=Paths.piantaByIndex(0);
|
||||
published=check(
|
||||
target.path(InterfaceConstants.Methods.DELETE_FILES_PATH).path(published.getMongo_id()).
|
||||
request(MediaType.APPLICATION_JSON).post(Entity.entity(path, MediaType.APPLICATION_JSON)),Concessione.class);
|
||||
|
||||
assertTrue(published.getPianteFineScavo().get(0).getActualContent().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publish() throws Exception {
|
||||
|
|
Reference in New Issue