{DEV] correct some error in the uopload files

This commit is contained in:
Edouard DUPIN 2023-04-10 21:56:40 +02:00
parent 7569516916
commit ff0bb5743f
4 changed files with 34 additions and 51 deletions

View File

@ -4,15 +4,9 @@
<artifactId>karideo</artifactId>
<version>0.1.0</version>
<properties>
<jaxrs.version>2.1</jaxrs.version>
<jersey.version>2.32</jersey.version>
<jaxb.version>2.3.1</jaxb.version>
<istack.version>3.0.7</istack.version>
<maven.compiler.version>3.1</maven.compiler.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.dependency.version>3.1.1</maven.dependency.version>
</properties>
<repositories>
@ -26,21 +20,10 @@
<dependency>
<groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId>
<version>0.3.1</version>
<version>0.3.3</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<sourceDirectory>src</sourceDirectory>
@ -62,13 +45,14 @@
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<mainClass>io.scenarium.oauth.WebLauncher</mainClass>
<mainClass>org.kar.karideo.WebLauncher</mainClass>
</configuration>
</plugin>
<!-- Create the source bundle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>

View File

@ -10,7 +10,6 @@ import org.kar.karideo.model.Media;
import org.kar.karideo.model.Season;
import org.kar.karideo.model.Series;
import org.kar.karideo.model.Type;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.UpdateJwtPublicKey;
import org.kar.archidata.api.DataResource;
@ -90,8 +89,6 @@ public class WebLauncher {
// enable this to show low level request
//rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName());
System.out.println(" ==> " + GlobalConfiguration.dbConfig);
System.out.println("OAuth service " + getBaseURI());
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
@ -114,7 +111,6 @@ public class WebLauncher {
try {
server.start();
System.out.println("Jersey app started at " + getBaseURI());
System.out.println("Press CTRL^C to exit..");
Thread.currentThread().join();
} catch (Exception e) {
System.out.println("There was an error while starting Grizzly HTTP server.");

View File

@ -11,6 +11,8 @@ import org.kar.karideo.model.Type;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.exception.FailException;
import org.kar.archidata.exception.InputException;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
@ -75,7 +77,7 @@ public class VideoResource {
@FormDataParam("typeId") String typeId,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData
) {
) throws FailException {
try {
// correct input string stream :
fileName = multipartCorrection(fileName);
@ -99,10 +101,7 @@ public class VideoResource {
System.out.println(" - fileMetaData: " + fileMetaData);
System.out.flush();
if (typeId == null) {
return Response.status(406).
entity("Missong Input 'type'").
type("text/plain").
build();
throw new InputException("typeId", "TypiId is not specified");
}
long tmpUID = DataResource.getTmpDataId();
@ -116,7 +115,7 @@ public class VideoResource {
} catch (IOException ex) {
DataResource.removeTemporaryFile(tmpUID);
ex.printStackTrace();
return Response.notModified("can not create input media").build();
throw new FailException("can not create input media (the data model has an internal error");
}
} else if (data.deleted == true) {
System.out.println("Data already exist but deleted");
@ -133,22 +132,25 @@ public class VideoResource {
Type typeNode = TypeResource.getId(Long.parseLong(typeId));
if (typeNode == null) {
DataResource.removeTemporaryFile(tmpUID);
return Response.notModified("TypeId does not exist ...").build();
throw new InputException("typeId", "TypeId does not exist ...");
}
System.out.println(" ==> " + typeNode);
System.out.println("Find seriesNode");
// get uid of group:
Series seriesNode = SeriesResource.getOrCreate(series, typeNode.id);
Series seriesNode = null;
if (series != null) {
seriesNode = SeriesResource.getOrCreate(series, typeNode.id);
}
System.out.println(" ==> " + seriesNode);
System.out.println("Find seasonNode");
// get uid of season:
Season seasonNode = null;
try {
seasonNode = SeasonResource.getOrCreate(season, seriesNode.id);
} catch (java.lang.NumberFormatException ex) {
// nothing to do ....
if (seriesNode == null && season != null) {
DataResource.removeTemporaryFile(tmpUID);
throw new InputException("season", "Season is set but no seraies is set !!");
}
seasonNode = SeasonResource.getOrCreate(season, seriesNode.id);
System.out.println(" ==> " + seasonNode);
System.out.println("add media");
@ -160,8 +162,14 @@ public class VideoResource {
media.name = title;
media.dataId = data.id;
media.typeId = typeNode.id;
media.seriesId = null;
if(seriesNode != null) {
media.seriesId = seriesNode.id;
}
media.seasonId = null;
if (seasonNode != null) {
media.seasonId = seasonNode.id;
}
media.episode = null;
if (episode != null || ! episode.contentEquals("")) {
media.episode = Integer.parseInt(episode);
@ -173,19 +181,14 @@ public class VideoResource {
return Response.ok(creation).build();
} catch (SQLException ex) {
ex.printStackTrace();
System.out.println("Catch error:" + ex.getMessage());
throw new FailException("Catch SQLerror ==> check server logs");
}
} catch (Exception ex) {
System.out.println("Catch an unexpected error ... " + ex.getMessage());
ex.printStackTrace();
return Response.status(417).
entity("Back-end error: " + ex.getMessage()).
type("text/plain").
build();
throw new FailException("Catch Exception ==> check server logs");
}
return Response.status(417).
entity("Back-end error").
type("text/plain").
build();
}
@POST
@Path("{id}/add_cover")