From ff0bb5743f7bb1980c5e538c5f61d7c6e58d6cdf Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 10 Apr 2023 21:56:40 +0200 Subject: [PATCH] {DEV] correct some error in the uopload files --- back/pom.xml | 28 +++------- back/src/org/kar/karideo/WebLauncher.java | 4 -- .../org/kar/karideo/api/VideoResource.java | 51 ++++++++++--------- back/src/org/kar/karideo/model/Season.java | 2 +- 4 files changed, 34 insertions(+), 51 deletions(-) diff --git a/back/pom.xml b/back/pom.xml index 336ea5d..c623d73 100644 --- a/back/pom.xml +++ b/back/pom.xml @@ -3,16 +3,10 @@ kar karideo 0.1.0 - - 2.1 - 2.32 - 2.3.1 - 3.0.7 - + 3.1 17 17 - 3.1.1 @@ -25,22 +19,11 @@ kangaroo-and-rabbit - archidata - 0.3.1 + archidata + 0.3.3 - - - - org.glassfish.jersey - jersey-bom - ${jersey.version} - pom - import - - - src @@ -62,13 +45,14 @@ exec-maven-plugin 1.4.0 - io.scenarium.oauth.WebLauncher + org.kar.karideo.WebLauncher org.apache.maven.plugins maven-source-plugin + 3.2.1 attach-sources @@ -187,4 +171,4 @@ - \ No newline at end of file + diff --git a/back/src/org/kar/karideo/WebLauncher.java b/back/src/org/kar/karideo/WebLauncher.java index bf95c10..d40ee09 100755 --- a/back/src/org/kar/karideo/WebLauncher.java +++ b/back/src/org/kar/karideo/WebLauncher.java @@ -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."); diff --git a/back/src/org/kar/karideo/api/VideoResource.java b/back/src/org/kar/karideo/api/VideoResource.java index 8420f08..8c6e8ad 100644 --- a/back/src/org/kar/karideo/api/VideoResource.java +++ b/back/src/org/kar/karideo/api/VideoResource.java @@ -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,23 +132,26 @@ 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 = seriesNode.id; - media.seasonId = seasonNode.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") diff --git a/back/src/org/kar/karideo/model/Season.java b/back/src/org/kar/karideo/model/Season.java index 14225ab..33dcf0a 100644 --- a/back/src/org/kar/karideo/model/Season.java +++ b/back/src/org/kar/karideo/model/Season.java @@ -29,4 +29,4 @@ public class Season extends GenericTable { @SQLComment("List of Id of the sopecific covers") @SQLTableLinkGeneric public List covers = null; -} +} \ No newline at end of file