Merge branch 'lastdev' of https://github.com/ArenMg/aren into lastdev

This commit is contained in:
Henintsoa 2021-11-25 17:26:50 +03:00
commit 35738311e3
3 changed files with 79 additions and 4 deletions

View file

@ -0,0 +1,13 @@
package fr.lirmm.aren.model.aaf;
public class UploadedFile {
private String name ;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View file

@ -82,6 +82,21 @@ public class DocumentService extends AbstractService<Document> {
return new HashSet<Document>(generateQuery(null, withDebates).getResultList()); return new HashSet<Document>(generateQuery(null, withDebates).getResultList());
} }
public Set<Document> findAllByType(boolean withDebates, String type){
TypedQuery<Document> query = getEntityManager().createQuery("SELECT do "
+ "FROM Document do "
+ (withDebates
? "LEFT JOIN FETCH do.debates d "
: "")
+ (type.equalsIgnoreCase("CARTO")
?"WHERE do.type = :type "
:"WHERE do.type = :type OR do.type = NULL "),
Document.class)
.setParameter("type",type);
return new HashSet<Document>(query.getResultList());
}
/** /**
* *
* @param document * @param document

View file

@ -1,14 +1,20 @@
package fr.lirmm.aren.ws.rest; package fr.lirmm.aren.ws.rest;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.ws.rs.POST; import javax.ws.rs.*;
import javax.ws.rs.Path; import javax.ws.rs.core.MediaType;
import javax.ws.rs.PathParam; import javax.ws.rs.core.Response;
import fr.lirmm.aren.model.aaf.UploadedFile;
import fr.lirmm.aren.service.DocumentService; import fr.lirmm.aren.service.DocumentService;
import fr.lirmm.aren.model.Document; import fr.lirmm.aren.model.Document;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import java.io.*;
import java.util.Set; import java.util.Set;
/** /**
@ -43,6 +49,13 @@ public class DocumentRESTFacade extends AbstractRESTFacade<Document> {
return documentService.findAll(withDebates); return documentService.findAll(withDebates);
} }
@Path("{type}")
@RolesAllowed({"MODO"})
public Set<Document> findAllByType(@PathParam("type") String type) {
boolean withDebates = this.overview == null;
return documentService.findAllByType(withDebates, type);
}
/** /**
* *
* @param id * @param id
@ -57,7 +70,7 @@ public class DocumentRESTFacade extends AbstractRESTFacade<Document> {
/** /**
* *
* @param id * @param doc
* @return * @return
*/ */
@Override @Override
@ -81,4 +94,38 @@ public class DocumentRESTFacade extends AbstractRESTFacade<Document> {
return this.create(document); return this.create(document);
} }
@POST
@Path("/map")
@PermitAll
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadPdfFile(@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception
{
File UPLOAD_PATH = new File("/tmp/img/");
if (! UPLOAD_PATH.exists()){
UPLOAD_PATH.mkdir();
}
UploadedFile uploadedFile=new UploadedFile() ;
try
{
int read = 0;
byte[] bytes = new byte[1024];
String filename=UPLOAD_PATH +"carto"+System.currentTimeMillis()+ fileMetaData.getFileName().substring(fileMetaData.getFileName().lastIndexOf(".")) ;
File file=new File(filename) ;
OutputStream out = new FileOutputStream(file);
while ((read = fileInputStream.read(bytes)) != -1)
{
out.write(bytes, 0, read);
}
out.flush();
out.close();
uploadedFile.setName(file.getAbsolutePath());
} catch (IOException e)
{
throw new WebApplicationException("Error while uploading file. Please try again !!");
}
return Response.status(200).entity(uploadedFile).build();
}
} }