[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,34 +216,21 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static <CLASS_TYPE, ID_TYPE> Response uploadCover(
|
|
||||||
final Class<CLASS_TYPE> clazz,
|
|
||||||
final ID_TYPE id,
|
|
||||||
String fileName,
|
|
||||||
final InputStream fileInputStream,
|
|
||||||
final FormDataContentDisposition fileMetaData) {
|
|
||||||
try {
|
|
||||||
// correct input string stream :
|
|
||||||
fileName = multipartCorrection(fileName);
|
|
||||||
|
|
||||||
// public NodeSmall uploadFile(final FormDataMultiPart form) {
|
// public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||||
LOGGER.info("Upload media file: {}", fileMetaData);
|
LOGGER.info("Upload media file: {}", fileMetaData);
|
||||||
LOGGER.info(" - id: {}", id);
|
LOGGER.info(" - id: {}", id);
|
||||||
LOGGER.info(" - file_name: ", fileName);
|
LOGGER.info(" - file_name: ", fileMetaData.getFileName());
|
||||||
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
||||||
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
||||||
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
return Response.notModified("Media Id does not exist or removed...").build();
|
throw new InputException(clazz.getCanonicalName(),
|
||||||
|
"[" + id.toString() + "] Id does not exist or removed...");
|
||||||
}
|
}
|
||||||
|
|
||||||
final long tmpUID = getTmpDataId();
|
final long tmpUID = getTmpDataId();
|
||||||
@ -250,15 +239,15 @@ public class DataTools {
|
|||||||
if (data == null) {
|
if (data == null) {
|
||||||
LOGGER.info("Need to add the data in the BDD ... ");
|
LOGGER.info("Need to add the data in the BDD ... ");
|
||||||
try {
|
try {
|
||||||
data = createNewData(tmpUID, fileName, sha512);
|
data = createNewData(tmpUID, fileMetaData.getFileName(), sha512);
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
removeTemporaryFile(tmpUID);
|
removeTemporaryFile(tmpUID);
|
||||||
ex.printStackTrace();
|
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||||
return Response.notModified("can not create input media").build();
|
clazz.getCanonicalName() + "[" + id.toString() + "] can not create input media", ex);
|
||||||
} catch (final SQLException ex) {
|
} catch (final SQLException ex) {
|
||||||
ex.printStackTrace();
|
|
||||||
removeTemporaryFile(tmpUID);
|
removeTemporaryFile(tmpUID);
|
||||||
return Response.notModified("Error in SQL insertion ...").build();
|
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||||
|
clazz.getCanonicalName() + "[" + id.toString() + "] Error in SQL insertion", ex);
|
||||||
}
|
}
|
||||||
} else if (data.deleted) {
|
} else if (data.deleted) {
|
||||||
LOGGER.error("Data already exist but deleted");
|
LOGGER.error("Data already exist but deleted");
|
||||||
@ -276,11 +265,5 @@ public class DataTools {
|
|||||||
} else {
|
} else {
|
||||||
throw new IOException("Fail to add Cover can not detect type...");
|
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