[FIX] throw when uploading data
This commit is contained in:
parent
b479414bc2
commit
906216f237
@ -22,6 +22,8 @@ import org.kar.archidata.dataAccess.QueryCondition;
|
|||||||
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
|
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
|
||||||
import org.kar.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
import org.kar.archidata.dataAccess.options.ReadAllColumn;
|
import org.kar.archidata.dataAccess.options.ReadAllColumn;
|
||||||
|
import org.kar.archidata.exception.FailException;
|
||||||
|
import org.kar.archidata.exception.InputException;
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -214,73 +216,54 @@ public class DataTools {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CLASS_TYPE, ID_TYPE> Response uploadCover(
|
public static <CLASS_TYPE, ID_TYPE> void uploadCover(
|
||||||
final Class<CLASS_TYPE> clazz,
|
final Class<CLASS_TYPE> clazz,
|
||||||
final ID_TYPE id,
|
final ID_TYPE id,
|
||||||
final InputStream fileInputStream,
|
final InputStream fileInputStream,
|
||||||
final FormDataContentDisposition fileMetaData) {
|
final FormDataContentDisposition fileMetaData) throws Exception {
|
||||||
return uploadCover(clazz, id, fileMetaData.getFileName(), fileInputStream, fileMetaData);
|
// public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||||
}
|
LOGGER.info("Upload media file: {}", fileMetaData);
|
||||||
|
LOGGER.info(" - id: {}", id);
|
||||||
@Deprecated
|
LOGGER.info(" - file_name: ", fileMetaData.getFileName());
|
||||||
public static <CLASS_TYPE, ID_TYPE> Response uploadCover(
|
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
||||||
final Class<CLASS_TYPE> clazz,
|
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
||||||
final ID_TYPE id,
|
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
||||||
String fileName,
|
if (media == null) {
|
||||||
final InputStream fileInputStream,
|
throw new InputException(clazz.getCanonicalName(),
|
||||||
final FormDataContentDisposition fileMetaData) {
|
"[" + id.toString() + "] Id does not exist or removed...");
|
||||||
try {
|
}
|
||||||
// correct input string stream :
|
|
||||||
fileName = multipartCorrection(fileName);
|
final long tmpUID = getTmpDataId();
|
||||||
|
final String sha512 = saveTemporaryFile(fileInputStream, tmpUID);
|
||||||
// public NodeSmall uploadFile(final FormDataMultiPart form) {
|
Data data = getWithSha512(sha512);
|
||||||
LOGGER.info("Upload media file: {}", fileMetaData);
|
if (data == null) {
|
||||||
LOGGER.info(" - id: {}", id);
|
LOGGER.info("Need to add the data in the BDD ... ");
|
||||||
LOGGER.info(" - file_name: ", fileName);
|
try {
|
||||||
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
data = createNewData(tmpUID, fileMetaData.getFileName(), sha512);
|
||||||
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
} catch (final IOException ex) {
|
||||||
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
removeTemporaryFile(tmpUID);
|
||||||
if (media == null) {
|
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||||
return Response.notModified("Media Id does not exist or removed...").build();
|
clazz.getCanonicalName() + "[" + id.toString() + "] can not create input media", ex);
|
||||||
}
|
} catch (final SQLException ex) {
|
||||||
|
removeTemporaryFile(tmpUID);
|
||||||
final long tmpUID = getTmpDataId();
|
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||||
final String sha512 = saveTemporaryFile(fileInputStream, tmpUID);
|
clazz.getCanonicalName() + "[" + id.toString() + "] Error in SQL insertion", ex);
|
||||||
Data data = getWithSha512(sha512);
|
}
|
||||||
if (data == null) {
|
} else if (data.deleted) {
|
||||||
LOGGER.info("Need to add the data in the BDD ... ");
|
LOGGER.error("Data already exist but deleted");
|
||||||
try {
|
undelete(data.uuid);
|
||||||
data = createNewData(tmpUID, fileName, sha512);
|
data.deleted = false;
|
||||||
} catch (final IOException ex) {
|
} else {
|
||||||
removeTemporaryFile(tmpUID);
|
LOGGER.error("Data already exist ... all good");
|
||||||
ex.printStackTrace();
|
}
|
||||||
return Response.notModified("can not create input media").build();
|
// Fist step: retrieve all the Id of each parents:...
|
||||||
} catch (final SQLException ex) {
|
LOGGER.info("Find typeNode");
|
||||||
ex.printStackTrace();
|
if (id instanceof final Long idLong) {
|
||||||
removeTemporaryFile(tmpUID);
|
AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
|
||||||
return Response.notModified("Error in SQL insertion ...").build();
|
} else if (id instanceof final UUID idUUID) {
|
||||||
}
|
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
||||||
} else if (data.deleted) {
|
} else {
|
||||||
LOGGER.error("Data already exist but deleted");
|
throw new IOException("Fail to add Cover can not detect type...");
|
||||||
undelete(data.uuid);
|
|
||||||
data.deleted = false;
|
|
||||||
} else {
|
|
||||||
LOGGER.error("Data already exist ... all good");
|
|
||||||
}
|
|
||||||
// Fist step: retrieve all the Id of each parents:...
|
|
||||||
LOGGER.info("Find typeNode");
|
|
||||||
if (id instanceof final Long idLong) {
|
|
||||||
AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
|
|
||||||
} else if (id instanceof final UUID idUUID) {
|
|
||||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
|
||||||
} else {
|
|
||||||
throw new IOException("Fail to add Cover can not detect type...");
|
|
||||||
}
|
|
||||||
return Response.ok(DataAccess.get(clazz, id)).build();
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
System.out.println("Cat ann unexpected error ... ");
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return Response.serverError().build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user