Compare commits

...

2 Commits

12 changed files with 94 additions and 116 deletions

View File

@ -99,7 +99,7 @@ public class WebLauncher {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
System.out.println("Stopping server.."); WebLauncher.LOGGER.info("Stopping server..");
serverLink.shutdownNow(); serverLink.shutdownNow();
} }
}, "shutdownHook")); }, "shutdownHook"));

View File

@ -2,14 +2,17 @@ package org.kar.archidata;
import org.kar.archidata.tools.ConfigBaseVariable; import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.archidata.tools.JWTWrapper; import org.kar.archidata.tools.JWTWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UpdateJwtPublicKey extends Thread { public class UpdateJwtPublicKey extends Thread {
private static final Logger LOGGER = LoggerFactory.getLogger(UpdateJwtPublicKey.class);
boolean kill = false; boolean kill = false;
@Override @Override
public void run() { public void run() {
if (ConfigBaseVariable.getSSOAddress() == null) { if (ConfigBaseVariable.getSSOAddress() == null) {
System.out.println("SSO INTERFACE is not provided ==> work alone."); LOGGER.warn("SSO INTERFACE is not provided ==> work alone.");
// No SO provided, kill the thread. // No SO provided, kill the thread.
return; return;
} }
@ -19,7 +22,7 @@ public class UpdateJwtPublicKey extends Thread {
JWTWrapper.initLocalTokenRemote(ConfigBaseVariable.getSSOAddress(), "archidata"); JWTWrapper.initLocalTokenRemote(ConfigBaseVariable.getSSOAddress(), "archidata");
} catch (final Exception e1) { } catch (final Exception e1) {
e1.printStackTrace(); e1.printStackTrace();
System.out.println("Can not retreive the basic tocken"); LOGGER.error("Can not retreive the basic tocken");
return; return;
} }
try { try {

View File

@ -21,6 +21,7 @@ import java.util.UUID;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bson.types.ObjectId;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam; import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.security.PermitTokenInURI; import org.kar.archidata.annotation.security.PermitTokenInURI;
@ -86,24 +87,25 @@ public class DataResource {
return filePath; return filePath;
} }
public static String getFileDataOld(final long tmpFolderId) { public static String getFileDataOld(final UUID uuid) {
final String filePath = ConfigBaseVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator final String stringUUID = uuid.toString();
final String filePath = ConfigBaseVariable.getMediaDataFolder() + File.separator + stringUUID + File.separator
+ "data"; + "data";
try { try {
createFolder(ConfigBaseVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator); createFolder(ConfigBaseVariable.getMediaDataFolder() + File.separator + stringUUID + File.separator);
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return filePath; return filePath;
} }
public static String getFileData(final UUID uuid) { public static String getFileData(final ObjectId oid) {
final String stringUUID = uuid.toString(); final String stringOid = oid.toHexString();
final String part1 = stringUUID.substring(0, 2); final String part1 = stringOid.substring(0, 2);
final String part2 = stringUUID.substring(2, 4); final String part2 = stringOid.substring(2, 4);
final String part3 = stringUUID.substring(4); final String part3 = stringOid.substring(4);
final String finalPath = part1 + File.separator + part2; final String finalPath = part1 + File.separator + part2;
String filePath = ConfigBaseVariable.getMediaDataFolder() + "_uuid" + File.separator + finalPath String filePath = ConfigBaseVariable.getMediaDataFolder() + "_oid" + File.separator + finalPath
+ File.separator; + File.separator;
try { try {
createFolder(filePath); createFolder(filePath);
@ -114,8 +116,8 @@ public class DataResource {
return filePath; return filePath;
} }
public static String getFileMetaData(final UUID uuid) { public static String getFileMetaData(final ObjectId oid) {
return getFileData(uuid) + ".json"; return getFileData(oid) + ".json";
} }
public Data getWithSha512(final String sha512) { public Data getWithSha512(final String sha512) {
@ -166,7 +168,7 @@ public class DataResource {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
final String mediaPath = getFileData(injectedData.uuid); final String mediaPath = getFileData(injectedData.oid);
LOGGER.info("src = {}", tmpPath); LOGGER.info("src = {}", tmpPath);
LOGGER.info("dst = {}", mediaPath); LOGGER.info("dst = {}", mediaPath);
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE); Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
@ -174,9 +176,9 @@ public class DataResource {
return injectedData; return injectedData;
} }
public static void modeFileOldModelToNewModel(final long id, final UUID uuid) throws IOException { public static void modeFileOldModelToNewModel(final UUID uuid, final ObjectId oid) throws IOException {
String mediaCurentPath = getFileDataOld(id); String mediaCurentPath = getFileDataOld(uuid);
String mediaDestPath = getFileData(uuid); String mediaDestPath = getFileData(oid);
LOGGER.info("src = {}", mediaCurentPath); LOGGER.info("src = {}", mediaCurentPath);
LOGGER.info("dst = {}", mediaDestPath); LOGGER.info("dst = {}", mediaDestPath);
if (Files.exists(Paths.get(mediaCurentPath))) { if (Files.exists(Paths.get(mediaCurentPath))) {
@ -252,9 +254,9 @@ public class DataResource {
return sb.toString(); return sb.toString();
} }
public Data getSmall(final UUID id) { public Data getSmall(final ObjectId oid) {
try { try {
return DataAccess.get(Data.class, id); return DataAccess.get(Data.class, oid);
} catch (final Exception e) { } catch (final Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -288,7 +290,7 @@ public class DataResource {
} }
@GET @GET
@Path("{uuid}") @Path("{oid}")
@PermitTokenInURI @PermitTokenInURI
@RolesAllowed("USER") @RolesAllowed("USER")
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@ -297,17 +299,17 @@ public class DataResource {
@Context final SecurityContext sc, @Context final SecurityContext sc,
@QueryParam(HttpHeaders.AUTHORIZATION) final String token, @QueryParam(HttpHeaders.AUTHORIZATION) final String token,
@HeaderParam("Range") final String range, @HeaderParam("Range") final String range,
@PathParam("uuid") final UUID uuid) throws FailException { @PathParam("oid") final ObjectId oid) throws FailException {
final GenericContext gc = (GenericContext) sc.getUserPrincipal(); final GenericContext gc = (GenericContext) sc.getUserPrincipal();
// logger.info("==================================================="); // logger.info("===================================================");
LOGGER.info("== DATA retrieveDataId ? id={} user={}", uuid, (gc == null ? "null" : gc.userByToken)); LOGGER.info("== DATA retrieveDataId ? oid={} user={}", oid, (gc == null ? "null" : gc.userByToken));
// logger.info("==================================================="); // logger.info("===================================================");
final Data value = getSmall(uuid); final Data value = getSmall(oid);
if (value == null) { if (value == null) {
return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build(); return Response.status(404).entity("media NOT FOUND: " + oid).type("text/plain").build();
} }
try { try {
return buildStream(getFileData(uuid), range, return buildStream(getFileData(oid), range,
value.mimeType == null ? "application/octet-stream" : value.mimeType); value.mimeType == null ? "application/octet-stream" : value.mimeType);
} catch (final Exception ex) { } catch (final Exception ex) {
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex); throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex);
@ -315,7 +317,7 @@ public class DataResource {
} }
@GET @GET
@Path("thumbnail/{uuid}") @Path("thumbnail/{oid}")
@RolesAllowed("USER") @RolesAllowed("USER")
@PermitTokenInURI @PermitTokenInURI
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@ -325,19 +327,19 @@ public class DataResource {
@Context final SecurityContext sc, @Context final SecurityContext sc,
@QueryParam(HttpHeaders.AUTHORIZATION) final String token, @QueryParam(HttpHeaders.AUTHORIZATION) final String token,
@HeaderParam("Range") final String range, @HeaderParam("Range") final String range,
@PathParam("uuid") final UUID uuid) throws FailException { @PathParam("oid") final ObjectId oid) throws FailException {
final GenericContext gc = (GenericContext) sc.getUserPrincipal(); final GenericContext gc = (GenericContext) sc.getUserPrincipal();
LOGGER.info("==================================================="); LOGGER.info("===================================================");
LOGGER.info("== DATA retrieveDataThumbnailId ? {}", (gc == null ? "null" : gc.userByToken)); LOGGER.info("== DATA retrieveDataThumbnailId ? {}", (gc == null ? "null" : gc.userByToken));
LOGGER.info("==================================================="); LOGGER.info("===================================================");
final Data value = getSmall(uuid); final Data value = getSmall(oid);
if (value == null) { if (value == null) {
return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build(); return Response.status(404).entity("media NOT FOUND: " + oid).type("text/plain").build();
} }
final String filePathName = getFileData(uuid); final String filePathName = getFileData(oid);
final File inputFile = new File(filePathName); final File inputFile = new File(filePathName);
if (!inputFile.exists()) { if (!inputFile.exists()) {
return Response.status(404).entity("{\"error\":\"media Does not exist: " + uuid + "\"}") return Response.status(404).entity("{\"error\":\"media Does not exist: " + oid + "\"}")
.type("application/json").build(); .type("application/json").build();
} }
if (value.mimeType.contentEquals("image/jpeg") || value.mimeType.contentEquals("image/png") if (value.mimeType.contentEquals("image/jpeg") || value.mimeType.contentEquals("image/png")
@ -402,7 +404,7 @@ public class DataResource {
} }
@GET @GET
@Path("{uuid}/{name}") @Path("{oid}/{name}")
@PermitTokenInURI @PermitTokenInURI
@RolesAllowed("USER") @RolesAllowed("USER")
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@ -411,17 +413,17 @@ public class DataResource {
@Context final SecurityContext sc, @Context final SecurityContext sc,
@QueryParam(HttpHeaders.AUTHORIZATION) final String token, @QueryParam(HttpHeaders.AUTHORIZATION) final String token,
@HeaderParam("Range") final String range, @HeaderParam("Range") final String range,
@PathParam("uuid") final UUID uuid, @PathParam("oid") final ObjectId oid,
@PathParam("name") final String name) throws Exception { @PathParam("name") final String name) throws Exception {
final GenericContext gc = (GenericContext) sc.getUserPrincipal(); final GenericContext gc = (GenericContext) sc.getUserPrincipal();
// logger.info("==================================================="); // logger.info("===================================================");
LOGGER.info("== DATA retrieveDataFull ? id={} user={}", uuid, (gc == null ? "null" : gc.userByToken)); LOGGER.info("== DATA retrieveDataFull ? id={} user={}", oid, (gc == null ? "null" : gc.userByToken));
// logger.info("==================================================="); // logger.info("===================================================");
final Data value = getSmall(uuid); final Data value = getSmall(oid);
if (value == null) { if (value == null) {
return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build(); return Response.status(404).entity("media NOT FOUND: " + oid).type("text/plain").build();
} }
return buildStream(getFileData(uuid), range, return buildStream(getFileData(oid), range,
value.mimeType == null ? "application/octet-stream" : value.mimeType); value.mimeType == null ? "application/octet-stream" : value.mimeType);
} }

View File

@ -529,7 +529,7 @@ public class DBAccessMorphia extends DBAccess {
final Document insertedDocument = collection.find(new Document("_id", insertedId)).first(); final Document insertedDocument = collection.find(new Document("_id", insertedId)).first();
// Afficher le document récupéré // Afficher le document récupéré
System.out.println("Inserted document: " + insertedDocument); LOGGER.trace("Inserted document: " + insertedDocument);
} catch (final Exception ex) { } catch (final Exception ex) {
LOGGER.error("Fail SQL request: {}", ex.getMessage()); LOGGER.error("Fail SQL request: {}", ex.getMessage());

View File

@ -207,39 +207,6 @@ public class DBAccessSQL extends DBAccess {
return out; return out;
} }
/** Extract a list of UUID with "-" separated element from a SQL input data.
* @param rs Result Set of the BDD
* @param iii Id in the result set
* @return The list of Long value
* @throws SQLException if an error is generated in the SQL request. */
public List<UUID> getListOfUUIDs(final ResultSet rs, final int iii, final String separator) throws SQLException {
final String trackString = rs.getString(iii);
if (rs.wasNull()) {
return null;
}
final List<UUID> out = new ArrayList<>();
final String[] elements = trackString.split(separator);
for (final String elem : elements) {
final UUID tmp = UUID.fromString(elem);
out.add(tmp);
}
return out;
}
public List<ObjectId> getListOfOIDs(final ResultSet rs, final int iii, final String separator) throws SQLException {
final String trackString = rs.getString(iii);
if (rs.wasNull()) {
return null;
}
final List<ObjectId> out = new ArrayList<>();
final String[] elements = trackString.split(separator);
for (final String elem : elements) {
final ObjectId tmp = new ObjectId(elem);
out.add(tmp);
}
return out;
}
public byte[][] splitIntoGroupsOf16Bytes(final byte[] input) { public byte[][] splitIntoGroupsOf16Bytes(final byte[] input) {
final int inputLength = input.length; final int inputLength = input.length;
final int numOfGroups = (inputLength + 15) / 16; // Calculate the number of groups needed final int numOfGroups = (inputLength + 15) / 16; // Calculate the number of groups needed
@ -309,8 +276,8 @@ public class DBAccessSQL extends DBAccess {
if (tmp == null) { if (tmp == null) {
ps.setNull(iii.value, Types.BINARY); ps.setNull(iii.value, Types.BINARY);
} else { } else {
final String dataString = ((ObjectId) tmp).toHexString(); final byte[] dataByte = ((ObjectId) tmp).toByteArray();
ps.setString(iii.value, dataString); ps.setBytes(iii.value, dataByte);
} }
} else if (type == UUID.class) { } else if (type == UUID.class) {
final Object tmp = field.get(data); final Object tmp = field.get(data);
@ -432,7 +399,7 @@ public class DBAccessSQL extends DBAccess {
final ResultSet rs, final ResultSet rs,
final CountInOut countNotNull) throws Exception { final CountInOut countNotNull) throws Exception {
if (type == ObjectId.class) { if (type == ObjectId.class) {
final String tmp = rs.getString(count.value); final byte[] tmp = rs.getBytes(count.value);
if (rs.wasNull()) { if (rs.wasNull()) {
field.set(data, null); field.set(data, null);
} else { } else {
@ -623,7 +590,7 @@ public class DBAccessSQL extends DBAccess {
final Class<?> type = field.getType(); final Class<?> type = field.getType();
if (type == ObjectId.class) { if (type == ObjectId.class) {
return (final ResultSet rs, final Object obj) -> { return (final ResultSet rs, final Object obj) -> {
final String tmp = rs.getString(count); final byte[] tmp = rs.getBytes(count);
if (rs.wasNull()) { if (rs.wasNull()) {
field.set(obj, null); field.set(obj, null);
} else { } else {
@ -1055,12 +1022,12 @@ public class DBAccessSQL extends DBAccess {
if (primaryKeyField.getType() == UUID.class) { if (primaryKeyField.getType() == UUID.class) {
// uniqueSQLUUID = generatedKeys.getObject(1, UUID.class); // uniqueSQLUUID = generatedKeys.getObject(1, UUID.class);
/* final Object obj = generatedKeys.getObject(1); final BigInteger bigint = (BigInteger) generatedKeys.getObject(1); uniqueSQLUUID = UuidUtils.asUuid(bigint); final UUID /* final Object obj = generatedKeys.getObject(1); final BigInteger bigint = (BigInteger) generatedKeys.getObject(1); uniqueSQLUUID = UuidUtils.asUuid(bigint); final UUID
* generatedUUID = (UUID) generatedKeys.getObject(1); System.out.println("UUID généré: " + generatedUUID); */ * generatedUUID = (UUID) generatedKeys.getObject(1); LOGGER.trace("UUID généré: " + generatedUUID); */
//final Object obj = generatedKeys.getObject(1); //final Object obj = generatedKeys.getObject(1);
final byte[] tmpid = generatedKeys.getBytes(1); final byte[] tmpid = generatedKeys.getBytes(1);
uniqueSQLUUID = UuidUtils.asUuid(tmpid); uniqueSQLUUID = UuidUtils.asUuid(tmpid);
} else if (primaryKeyField.getType() == ObjectId.class) { } else if (primaryKeyField.getType() == ObjectId.class) {
final String tmpid = generatedKeys.getString(1); final byte[] tmpid = generatedKeys.getBytes(1);
uniqueSQLOID = new ObjectId(tmpid); uniqueSQLOID = new ObjectId(tmpid);
} else { } else {
uniqueSQLID = generatedKeys.getLong(1); uniqueSQLID = generatedKeys.getLong(1);
@ -1245,12 +1212,13 @@ public class DBAccessSQL extends DBAccess {
return; return;
} }
if (value instanceof final UUID tmp) { if (value instanceof final UUID tmp) {
LOGGER.debug("Inject uuid => {}", tmp);
final byte[] dataByte = UuidUtils.asBytes(tmp); final byte[] dataByte = UuidUtils.asBytes(tmp);
ps.setBytes(iii.value, dataByte); ps.setBytes(iii.value, dataByte);
} else if (value instanceof final ObjectId tmp) { } else if (value instanceof final ObjectId tmp) {
final String dataString = tmp.toHexString(); final byte[] dataByte = tmp.toByteArray();
LOGGER.debug("Inject oid => {}", dataString); LOGGER.debug("Inject oid => {}", tmp.toHexString());
ps.setString(iii.value, dataString); ps.setBytes(iii.value, dataByte);
} else if (value instanceof final Long tmp) { } else if (value instanceof final Long tmp) {
LOGGER.debug("Inject Long => {}", tmp); LOGGER.debug("Inject Long => {}", tmp);
ps.setLong(iii.value, tmp); ps.setLong(iii.value, tmp);

View File

@ -37,8 +37,7 @@ public class DataFactory {
return "binary(16)"; return "binary(16)";
} }
if (type == ObjectId.class) { if (type == ObjectId.class) {
return "varchar(24)"; return "binary(12)";
// return "binary(12)";
} }
if (type == Long.class || type == long.class) { if (type == Long.class || type == long.class) {
return "bigint"; return "bigint";
@ -95,8 +94,7 @@ public class DataFactory {
return "BINARY(16)"; return "BINARY(16)";
} }
if (type == ObjectId.class) { if (type == ObjectId.class) {
return "text"; return "BINARY(12)";
//return "BINARY(12)";
} }
if (type == Long.class || type == long.class) { if (type == Long.class || type == long.class) {
return "INTEGER"; return "INTEGER";

View File

@ -17,6 +17,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bson.types.ObjectId;
import org.glassfish.jersey.media.multipart.ContentDisposition; import org.glassfish.jersey.media.multipart.ContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.kar.archidata.catcher.RestErrorResponse; import org.kar.archidata.catcher.RestErrorResponse;
@ -157,6 +158,12 @@ public class TsGenerateApi {
tsModels.add(new TsClassElement(models, "ZodUUID", "UUID", "isUUID", "zod.string().uuid()", tsModels.add(new TsClassElement(models, "ZodUUID", "UUID", "isUUID", "zod.string().uuid()",
DefinedPosition.BASIC)); DefinedPosition.BASIC));
} }
models = api.getCompatibleModels(List.of(ObjectId.class));
if (models != null) {
tsModels.add(new TsClassElement(models, "ZodObjectId", "ObjectId", "isObjectId",
"zod.string().length(24, \"Invalid ObjectId length\").regex(/^[a-fA-F0-9]{24}$/, \"Invalid ObjectId format\")",
DefinedPosition.BASIC));
}
models = api.getCompatibleModels(List.of(Long.class, long.class)); models = api.getCompatibleModels(List.of(Long.class, long.class));
if (models != null) { if (models != null) {
tsModels.add( tsModels.add(

View File

@ -11,7 +11,7 @@ import jakarta.persistence.Table;
@Table(name = "data") @Table(name = "data")
@DataIfNotExists @DataIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Data extends UUIDGenericDataSoftDelete { public class Data extends OIDGenericDataSoftDelete {
@Column(length = 128, nullable = false) @Column(length = 128, nullable = false)
@Schema(description = "Sha512 of the data") @Schema(description = "Sha512 of the data")
public String sha512; public String sha512;

View File

@ -9,9 +9,9 @@ import jakarta.validation.constraints.NotNull;
public class OIDGenericData extends GenericTiming { public class OIDGenericData extends GenericTiming {
@Id @Id
//@jakarta.persistence.Id @jakarta.persistence.Id
@Column(nullable = false, unique = true) @Column(nullable = false, unique = true, name = "_id")
@Schema(description = "Unique ObjectID of the object", required = false, readOnly = true, example = "65161616841351") @Schema(description = "Unique ObjectID of the object", required = false, readOnly = true, example = "65161616841351")
@NotNull @NotNull
public ObjectId _id = null; public ObjectId oid = null;
} }

View File

@ -13,9 +13,9 @@ import java.security.NoSuchAlgorithmException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.apache.tika.Tika; import org.apache.tika.Tika;
import org.bson.types.ObjectId;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.kar.archidata.api.DataResource; import org.kar.archidata.api.DataResource;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
@ -121,7 +121,7 @@ public class DataTools {
return null; return null;
} }
final String mediaPath = DataResource.getFileData(out.uuid); final String mediaPath = DataResource.getFileData(out.oid);
LOGGER.info("src = {}", tmpPath); LOGGER.info("src = {}", tmpPath);
LOGGER.info("dst = {}", mediaPath); LOGGER.info("dst = {}", mediaPath);
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE); Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
@ -151,9 +151,9 @@ public class DataTools {
return createNewData(ioDb, tmpUID, originalFileName, sha512, mimeType); return createNewData(ioDb, tmpUID, originalFileName, sha512, mimeType);
} }
public static void undelete(final DBAccess ioDb, final UUID id) { public static void undelete(final DBAccess ioDb, final ObjectId oid) {
try { try {
ioDb.unsetDelete(Data.class, id); ioDb.unsetDelete(Data.class, oid);
} catch (final Exception e) { } catch (final Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -338,14 +338,14 @@ public class DataTools {
} }
} else if (data.deleted) { } else if (data.deleted) {
LOGGER.error("Data already exist but deleted"); LOGGER.error("Data already exist but deleted");
undelete(ioDb, data.uuid); undelete(ioDb, data.oid);
data.deleted = false; data.deleted = false;
} else { } else {
LOGGER.error("Data already exist ... all good"); LOGGER.error("Data already exist ... all good");
} }
// Fist step: retrieve all the Id of each parents:... // Fist step: retrieve all the Id of each parents:...
LOGGER.info("Find typeNode"); LOGGER.info("Find typeNode");
AddOnDataJson.addLink(ioDb, clazz, null, id, null, data.uuid); AddOnDataJson.addLink(ioDb, clazz, null, id, null, data.oid);
} }
public static <CLASS_TYPE, ID_TYPE> void uploadCover( public static <CLASS_TYPE, ID_TYPE> void uploadCover(
@ -384,13 +384,13 @@ public class DataTools {
} }
} else if (data.deleted) { } else if (data.deleted) {
LOGGER.error("Data already exist but deleted"); LOGGER.error("Data already exist but deleted");
undelete(ioDb, data.uuid); undelete(ioDb, data.oid);
data.deleted = false; data.deleted = false;
} else { } else {
LOGGER.error("Data already exist ... all good"); LOGGER.error("Data already exist ... all good");
} }
// Fist step: retrieve all the Id of each parents:... // Fist step: retrieve all the Id of each parents:...
LOGGER.info("Find typeNode"); LOGGER.info("Find typeNode");
AddOnDataJson.addLink(ioDb, clazz, null, id, null, data.uuid); AddOnDataJson.addLink(ioDb, clazz, null, id, null, data.oid);
} }
} }

View File

@ -68,22 +68,22 @@ public class WebLauncher {
public void plop(final String aaa) { public void plop(final String aaa) {
// List available Image Readers // List available Image Readers
System.out.println("Available Image Readers:"); WebLauncher.LOGGER.trace("Available Image Readers:");
final Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(aaa); final Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(aaa);
while (readers.hasNext()) { while (readers.hasNext()) {
final ImageReader reader = readers.next(); final ImageReader reader = readers.next();
System.out.println("Reader: " + reader.getOriginatingProvider().getDescription(null)); WebLauncher.LOGGER.trace("Reader: " + reader.getOriginatingProvider().getDescription(null));
System.out.println("Reader CN: " + reader.getOriginatingProvider().getPluginClassName()); WebLauncher.LOGGER.trace("Reader CN: " + reader.getOriginatingProvider().getPluginClassName());
// ImageIO.deregisterServiceProvider(reader.getOriginatingProvider()); // ImageIO.deregisterServiceProvider(reader.getOriginatingProvider());
} }
// List available Image Writers // List available Image Writers
System.out.println("\nAvailable Image Writers:"); WebLauncher.LOGGER.trace("\nAvailable Image Writers:");
final Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(aaa); final Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(aaa);
while (writers.hasNext()) { while (writers.hasNext()) {
final ImageWriter writer = writers.next(); final ImageWriter writer = writers.next();
System.out.println("Writer: " + writer.getOriginatingProvider().getDescription(null)); WebLauncher.LOGGER.trace("Writer: " + writer.getOriginatingProvider().getDescription(null));
System.out.println("Writer CN: " + writer.getOriginatingProvider().getPluginClassName()); WebLauncher.LOGGER.trace("Writer CN: " + writer.getOriginatingProvider().getPluginClassName());
} }
} }
@ -135,7 +135,7 @@ public class WebLauncher {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
System.out.println("Stopping server.."); LOGGER.warn("Stopping server..");
serverLink.shutdownNow(); serverLink.shutdownNow();
} }
}, "shutdownHook")); }, "shutdownHook"));

View File

@ -166,7 +166,7 @@ public class TestListJson {
final SerializeListAsJsonObjectId insertedData = ConfigureDb.da.insert(test); final SerializeListAsJsonObjectId insertedData = ConfigureDb.da.insert(test);
Assertions.assertNotNull(insertedData); Assertions.assertNotNull(insertedData);
Assertions.assertNotNull(insertedData._id); Assertions.assertNotNull(insertedData.oid);
Assertions.assertNotNull(insertedData.data); Assertions.assertNotNull(insertedData.data);
Assertions.assertEquals(5, insertedData.data.size()); Assertions.assertEquals(5, insertedData.data.size());
Assertions.assertEquals(test.data.get(0), insertedData.data.get(0)); Assertions.assertEquals(test.data.get(0), insertedData.data.get(0));
@ -177,10 +177,10 @@ public class TestListJson {
// Try to retrieve all the data: // Try to retrieve all the data:
final SerializeListAsJsonObjectId retrieve = ConfigureDb.da.get(SerializeListAsJsonObjectId.class, final SerializeListAsJsonObjectId retrieve = ConfigureDb.da.get(SerializeListAsJsonObjectId.class,
insertedData._id); insertedData.oid);
Assertions.assertNotNull(retrieve); Assertions.assertNotNull(retrieve);
Assertions.assertNotNull(retrieve._id); Assertions.assertNotNull(retrieve.oid);
Assertions.assertNotNull(retrieve.data); Assertions.assertNotNull(retrieve.data);
Assertions.assertEquals(5, retrieve.data.size()); Assertions.assertEquals(5, retrieve.data.size());
Assertions.assertEquals(test.data.get(0), retrieve.data.get(0)); Assertions.assertEquals(test.data.get(0), retrieve.data.get(0));
@ -199,38 +199,38 @@ public class TestListJson {
final SerializeListAsJsonObjectId insertedData = ConfigureDb.da.insert(test); final SerializeListAsJsonObjectId insertedData = ConfigureDb.da.insert(test);
Assertions.assertNotNull(insertedData); Assertions.assertNotNull(insertedData);
Assertions.assertNotNull(insertedData._id); Assertions.assertNotNull(insertedData.oid);
Assertions.assertNotNull(insertedData.data); Assertions.assertNotNull(insertedData.data);
Assertions.assertEquals(0, insertedData.data.size()); Assertions.assertEquals(0, insertedData.data.size());
final ObjectId firstDataInserted1 = new ObjectId(); final ObjectId firstDataInserted1 = new ObjectId();
final ObjectId firstDataInserted2 = new ObjectId(); final ObjectId firstDataInserted2 = new ObjectId();
final ObjectId firstDataInserted3 = new ObjectId(); final ObjectId firstDataInserted3 = new ObjectId();
AddOnDataJson.addLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData._id, "data", AddOnDataJson.addLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData.oid, "data",
firstDataInserted1); firstDataInserted1);
AddOnDataJson.addLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData._id, "data", AddOnDataJson.addLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData.oid, "data",
firstDataInserted2); firstDataInserted2);
AddOnDataJson.addLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData._id, "data", AddOnDataJson.addLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData.oid, "data",
firstDataInserted3); firstDataInserted3);
// Try to retrieve all the data: // Try to retrieve all the data:
SerializeListAsJsonObjectId retrieve = ConfigureDb.da.get(SerializeListAsJsonObjectId.class, insertedData._id); SerializeListAsJsonObjectId retrieve = ConfigureDb.da.get(SerializeListAsJsonObjectId.class, insertedData.oid);
Assertions.assertNotNull(retrieve); Assertions.assertNotNull(retrieve);
Assertions.assertNotNull(retrieve._id); Assertions.assertNotNull(retrieve.oid);
Assertions.assertNotNull(retrieve.data); Assertions.assertNotNull(retrieve.data);
Assertions.assertEquals(3, retrieve.data.size()); Assertions.assertEquals(3, retrieve.data.size());
Assertions.assertEquals(firstDataInserted1, retrieve.data.get(0)); Assertions.assertEquals(firstDataInserted1, retrieve.data.get(0));
Assertions.assertEquals(firstDataInserted2, retrieve.data.get(1)); Assertions.assertEquals(firstDataInserted2, retrieve.data.get(1));
Assertions.assertEquals(firstDataInserted3, retrieve.data.get(2)); Assertions.assertEquals(firstDataInserted3, retrieve.data.get(2));
AddOnDataJson.removeLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData._id, "data", AddOnDataJson.removeLink(ConfigureDb.da, SerializeListAsJsonObjectId.class, "_id", insertedData.oid, "data",
firstDataInserted2); firstDataInserted2);
// Try to retrieve all the data: // Try to retrieve all the data:
retrieve = ConfigureDb.da.get(SerializeListAsJsonObjectId.class, insertedData._id); retrieve = ConfigureDb.da.get(SerializeListAsJsonObjectId.class, insertedData.oid);
Assertions.assertNotNull(retrieve); Assertions.assertNotNull(retrieve);
Assertions.assertNotNull(retrieve._id); Assertions.assertNotNull(retrieve.oid);
Assertions.assertNotNull(retrieve.data); Assertions.assertNotNull(retrieve.data);
Assertions.assertEquals(2, retrieve.data.size()); Assertions.assertEquals(2, retrieve.data.size());
Assertions.assertEquals(firstDataInserted1, retrieve.data.get(0)); Assertions.assertEquals(firstDataInserted1, retrieve.data.get(0));