Commit bef967c6 authored by Valentin Suhnjov's avatar Valentin Suhnjov

RIHAKB-130. Remove user from TableEntryCreateLogic

parent eb00c5d5
......@@ -61,7 +61,7 @@ public class AuthInfoCreator {
+ "\"organizations\":[\"" + organizationCode + "\"]}";
QueryHolder queryHolder = QueryHolder.create(JsonHelper.GSON, json);
Map<String, Map<String, String>> names = changeLogic.doGetNames(queryHolder, authInfo);
Map<String, Map<String, String>> names = changeLogic.doGetNames(queryHolder);
authInfo.setOrg_name(names.get("organizations").get(authInfo3rdParty.getAsutus()));
authInfo.setUser_name(names.get("persons").get(authInfo3rdParty.getIsikuKood()));
......
......@@ -81,7 +81,7 @@ public class ImportLogic {
FilterComponent fc2 = new FilterComponent("end_date", "null_or_>", dateJson);
List<ObjectNode> many = changeLogic.doGetMany(Main_resource.class, 1, 0, Arrays.asList(fc, fc2), "-creation_date",
null, user);
null);
if (many.isEmpty()) {
// no corresponding Main_resource in database
......@@ -148,8 +148,8 @@ public class ImportLogic {
List<String> arrayFieldsWithObjects, JsonObject importJson, AuthInfo user) throws RihaRestException,
ReflectiveOperationException, IOException {
List<ObjectNode> dataObjects = changeLogic.doGetByMainResourceId(Data_object.class, main_resource_id, user);
List<ObjectNode> documents = changeLogic.doGetByMainResourceId(Document.class, main_resource_id, user);
List<ObjectNode> dataObjects = changeLogic.doGetByMainResourceId(Data_object.class, main_resource_id);
List<ObjectNode> documents = changeLogic.doGetByMainResourceId(Document.class, main_resource_id);
List<ObjectNode> services = serviceLogic.getServicesByParentId(main_resource_id, user);
// updateOrDeleteConnectedObjects(dataObjects, uriToJsonObject, Data_object.class, user);
......@@ -169,8 +169,7 @@ public class ImportLogic {
importJson.remove(arrayField);
}
// update Main_resource
changeLogic.doUpdate(importJson.toString(), Main_resource.class, main_resource_id, null,
user);
changeLogic.doUpdate(importJson.toString(), Main_resource.class, main_resource_id, null);
}
/**
......@@ -190,9 +189,9 @@ public class ImportLogic {
changeLogic.replaceKindWithKindId(jsonObjectCopy);
// create imported Main_resource
List<Integer> createdKeys = changeLogic.doCreate(jsonObjectCopy.toString(), Main_resource.class, user);
List<Integer> createdKeys = changeLogic.doCreate(jsonObjectCopy.toString(), Main_resource.class);
int main_resourceId = createdKeys.get(0);
return (ObjectNode) changeLogic.doGet(Main_resource.class, main_resourceId, null, user);
return (ObjectNode) changeLogic.doGet(Main_resource.class, main_resourceId, null);
}
......@@ -224,7 +223,7 @@ public class ImportLogic {
jsonToCreate.remove(documentField);
}
// create connected data
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz, user);
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz);
int dataObjectId = createdKeys.get(0);
// create Docuemnts connected to data
......@@ -233,7 +232,7 @@ public class ImportLogic {
JsonObject jsonDoc = entryDoc.getValue();
jsonDoc.addProperty("data_object_id", dataObjectId);
changeLogic.replaceKindWithKindId(jsonDoc);
changeLogic.doCreate(jsonDoc.toString(), Document.class, user);
changeLogic.doCreate(jsonDoc.toString(), Document.class);
}
} else if (clazz == Main_resource.class) {
LOG.info("Creating special Main_resource services");
......@@ -250,7 +249,7 @@ public class ImportLogic {
jsonToCreate.remove(documentField);
}
// create connected data
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz, user);
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz);
int serviceId = createdKeys.get(0);
// create Docuemnts connected to data
......@@ -259,11 +258,11 @@ public class ImportLogic {
JsonObject jsonDoc = entryDoc.getValue();
jsonDoc.addProperty("main_resource_id", serviceId);
changeLogic.replaceKindWithKindId(jsonDoc);
changeLogic.doCreate(jsonDoc.toString(), Document.class, user);
changeLogic.doCreate(jsonDoc.toString(), Document.class);
}
} else {
// create connected data
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz, user);
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz);
}
}
......@@ -294,7 +293,7 @@ public class ImportLogic {
changeLogic.replaceKindWithKindId(jsonToCreate);
// create connected data
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz, user);
List<Integer> createdKeys = changeLogic.doCreate(jsonToCreate.toString(), clazz);
}
......@@ -321,11 +320,11 @@ public class ImportLogic {
int objId = connectedObj.get(pkField).asInt();
if (uriToJsonObject.containsKey(objUri)) {
LOG.info("Update exists");
changeLogic.doUpdate(uriToJsonObject.get(objUri).toString(), clazz, objId, null, user);
changeLogic.doUpdate(uriToJsonObject.get(objUri).toString(), clazz, objId, null);
// update item
} else {
LOG.info("Delete does not exist " + objUri);
changeLogic.doDelete(clazz.getSimpleName(), objId, user);
changeLogic.doDelete(clazz.getSimpleName(), objId);
// delete item
}
// remove uri so only those that must be created remain
......@@ -371,8 +370,7 @@ public class ImportLogic {
// check if connectedObj has nested Documents
FilterComponent fc = new FilterComponent("data_object_id", "=", "" + dataId);
List<ObjectNode> documents = changeLogic.doGetMany(Document.class, null, null, Arrays.asList(fc), null, null,
user);
List<ObjectNode> documents = changeLogic.doGetMany(Document.class, null, null, Arrays.asList(fc), null, null);
if (documents.size() > 0) {
// update or delete
LOG.info("SHOULD UPDATE OR DELETE NESTED DOCUEMNT ");
......@@ -387,11 +385,11 @@ public class ImportLogic {
uriToJsonObject.get(dataUri).remove(arrayField);
}
changeLogic.doUpdate(uriToJsonObject.get(dataUri).toString(), clazz, dataId, null, user);
changeLogic.doUpdate(uriToJsonObject.get(dataUri).toString(), clazz, dataId, null);
// update item
} else {
LOG.info("Delete Data_object does not exist " + dataUri);
changeLogic.doDelete(clazz.getSimpleName(), dataId, user);
changeLogic.doDelete(clazz.getSimpleName(), dataId);
// delete item
}
// remove uri so only those that must be created remain
......@@ -437,8 +435,7 @@ public class ImportLogic {
// check if connectedObj has nested Documents
FilterComponent fc = new FilterComponent("main_resource_id", "=", "" + serviceId);
List<ObjectNode> documents = changeLogic.doGetMany(Document.class, null, null, Arrays.asList(fc), null, null,
user);
List<ObjectNode> documents = changeLogic.doGetMany(Document.class, null, null, Arrays.asList(fc), null, null);
if (documents.size() > 0) {
// update or delete
LOG.info("SHOULD UPDATE OR DELETE NESTED DOCUEMNT ");
......@@ -453,11 +450,11 @@ public class ImportLogic {
uriToJsonObject.get(serviceUri).remove(arrayField);
}
changeLogic.doUpdate(uriToJsonObject.get(serviceUri).toString(), clazz, serviceId, null, user);
changeLogic.doUpdate(uriToJsonObject.get(serviceUri).toString(), clazz, serviceId, null);
// update item
} else {
LOG.info("Delete service does not exist " + serviceUri);
changeLogic.doDelete(clazz.getSimpleName(), serviceId, user);
changeLogic.doDelete(clazz.getSimpleName(), serviceId);
// delete item
}
// remove uri so only those that must be created remain
......@@ -573,7 +570,7 @@ public class ImportLogic {
List<FilterComponent> versionNameAlreadyUsed = Arrays.asList(
new FilterComponent("uri", "=", uri), new FilterComponent("version", "=", version));
List<ObjectNode> itemsWithSameVersion = changeLogic.doGetMany(Main_resource.class, null, null,
versionNameAlreadyUsed, null, null, user);
versionNameAlreadyUsed, null, null);
Validator.versionMustBeDifferent(itemsWithSameVersion, uri, version, jsonObject);
}
}
......@@ -100,15 +100,14 @@ public class NewVersionLogic<T, K> {
// actually List<ObjectNode>
// List<T> many = doGetMany(classRepresentingTable, 1, 0, Arrays.asList(fc), "-creation_date", null, null);
List<T> many = changeLogic.doGetMany(classRepresentingTable, 1, 0, Arrays.asList(fc), "-creation_date", null,
(AuthInfo) user);
List<T> many = changeLogic.doGetMany(classRepresentingTable, 1, 0, Arrays.asList(fc), "-creation_date", null);
Validator.noSuchUriInGivenTable(many, uri);
// check if given uri with given version already exists?
List<FilterComponent> versionNameAlreadyUsed = Arrays.asList(
new FilterComponent("uri", "=", uri), new FilterComponent("version", "=", newVersion));
List<T> itemsWithSameVersion = changeLogic.doGetMany(classRepresentingTable, null, null,
versionNameAlreadyUsed, null, null, (AuthInfo) user);
versionNameAlreadyUsed, null, null);
Validator.versionMustBeDifferent(itemsWithSameVersion, uri, newVersion, query);
T temp = many.get(0);
......@@ -133,14 +132,14 @@ public class NewVersionLogic<T, K> {
// 4. save temp (with new id)
// method throws RihaRestException
T itemTemp = (T) tableEntryCreateLogic.fromJsonContentToObjKeepExisting(tempJson.toString(),
classRepresentingTable, user);
classRepresentingTable);
// genericDAO.create(itemTemp);
List<Integer> archivedKeys = (List<Integer>) secureDAO.create(itemTemp);
// doCreate(tempJson.toString(), classRepresentingTable, user);
// temp = doGet(classRepresentingTable, id, null, null);
temp = changeLogic.doGet(classRepresentingTable, id, null, (AuthInfo) user);
temp = changeLogic.doGet(classRepresentingTable, id, null);
ObjectNode oldJson = (ObjectNode) temp;
// 5. update version of old
......@@ -167,7 +166,7 @@ public class NewVersionLogic<T, K> {
noLogicDAO.update(item);
// 9. return old (modfiied with new version)
// temp = doGet(classRepresentingTable, id, null, null);
temp = changeLogic.doGet(classRepresentingTable, id, null, (AuthInfo) user);
temp = changeLogic.doGet(classRepresentingTable, id, null);
doNewVersionDocument((Class<T>) Document.class, id, archivedKeys.get(0), dateJson, (AuthInfo) user);
doNewVersionData_object((Class<T>) Data_object.class, id, archivedKeys.get(0), dateJson, (AuthInfo) user);
......@@ -222,7 +221,7 @@ public class NewVersionLogic<T, K> {
// List<ObjectNode> actually
List<T> connectedDocs = changeLogic.doGetMany((Class<T>) Document.class, null, null, Arrays.asList(filterById),
null, null, user);
null, null);
// for each Document create copy (with new id), set End_date on copy, set archived main_resource_id
......@@ -253,7 +252,7 @@ public class NewVersionLogic<T, K> {
LOG.info("Archiving doc " + docJson);
T itemTemp = (T) tableEntryCreateLogic.fromJsonContentToObjKeepExisting(docJson.toString(),
clazz, user);
clazz);
// save archived item to database
List<Integer> createdKeys = (List<Integer>) secureDAO.create(itemTemp);
docIdMap.put(id, createdKeys.get(0));
......@@ -262,8 +261,7 @@ public class NewVersionLogic<T, K> {
LOG.info("Map of current doc ids to archived doc ids " + docIdMap);
// get unmodified connected Documents
connectedDocs = changeLogic.doGetMany((Class<T>) Document.class, null, null, Arrays.asList(filterById), null, null,
user);
connectedDocs = changeLogic.doGetMany((Class<T>) Document.class, null, null, Arrays.asList(filterById), null, null);
// for each Document (original) set Start_date, set
for (T connectedDoc : connectedDocs) {
......@@ -327,7 +325,7 @@ public class NewVersionLogic<T, K> {
// List<ObjectNode> actually
List<T> connectedData_objects = changeLogic.doGetMany((Class<T>) Data_object.class, null, null,
Arrays.asList(filterByMR),
null, null, user);
null, null);
// arr[0] is currentId, arr[1] is archivedId
Map<String, int[]> uriToDataIdMap = new HashMap<>();
......@@ -350,14 +348,14 @@ public class NewVersionLogic<T, K> {
dataJson.remove("kind");
T itemTemp = (T) tableEntryCreateLogic.fromJsonContentToObjKeepExisting(dataJson.toString(),
clazz, user);
clazz);
// save archived item to database
List<Integer> createdKeys = (List<Integer>) secureDAO.create(itemTemp);
}
// get unmodified connected Data_objects
connectedData_objects = changeLogic.doGetMany((Class<T>) Data_object.class, null, null,
Arrays.asList(filterByMR), null, null, user);
Arrays.asList(filterByMR), null, null);
// for each Data_object (original) set Start_date, set modifier
for (T connectedData : connectedData_objects) {
......@@ -381,7 +379,7 @@ public class NewVersionLogic<T, K> {
// get archived data_object ids
FilterComponent filterByMRArchived = new FilterComponent("main_resource_id", "=", "" + archivedMain_resourceId);
List<T> justArchivedData = changeLogic.doGetMany((Class<T>) Data_object.class, null, null,
Arrays.asList(filterByMRArchived), null, null, user);
Arrays.asList(filterByMRArchived), null, null);
// add archived data_object ids to uriToDataIdMap
for (T connectedData : justArchivedData) {
ObjectNode dataJson = (ObjectNode) connectedData;
......
......@@ -98,8 +98,7 @@ public class ServiceLogic<T, K> {
}
}
List<T> all = changeLogic.doGetMany(classRepresentingTable, limit, offset, filterComponents, sort, fields,
authInfo);
List<T> all = changeLogic.doGetMany(classRepresentingTable, limit, offset, filterComponents, sort, fields);
return Response.ok(all).build();
} catch (RihaRestException e) {
......@@ -130,7 +129,7 @@ public class ServiceLogic<T, K> {
Validator.unknownTableRequested(tableName);
Class<T> classRepresentingTable = Finals.getClassRepresentingTable(tableName);
T item = changeLogic.doGet(classRepresentingTable, id, fields, authInfo);
T item = changeLogic.doGet(classRepresentingTable, id, fields);
Validator.noSuchIdInGivenTable(item, id);
......@@ -158,15 +157,15 @@ public class ServiceLogic<T, K> {
public Response getResourceById(Integer id, AuthInfo authInfo) {
try {
T item = changeLogic.doGet((Class<T>) Main_resource.class, id, null, authInfo);
T item = changeLogic.doGet((Class<T>) Main_resource.class, id, null);
Validator.noSuchIdInGivenTable(item, id);
List<T> documents = changeLogic.doGetByMainResourceId((Class<T>) Document.class, id, authInfo);
List<T> documents = changeLogic.doGetByMainResourceId((Class<T>) Document.class, id);
FileHelper.readDocumentFileToContent(documents, Document.class);
Map<String, List<T>> fieldNameMap = extractItemsByFieldName(documents, Document.class);
List<T> dataObjects = changeLogic.doGetByMainResourceId((Class<T>) Data_object.class, id, authInfo);
List<T> dataObjects = changeLogic.doGetByMainResourceId((Class<T>) Data_object.class, id);
// get documents connnected to data_object
addDocumentsToData_object(dataObjects, authInfo);
......@@ -210,7 +209,7 @@ public class ServiceLogic<T, K> {
// get services only
FilterComponent fcService = new FilterComponent("kind", "=", "service");
List<T> servcies = changeLogic.doGetMany((Class<T>) Main_resource.class, 1, 0, Arrays.asList(fc, fcService),
null, null, authInfo);
null, null);
return servcies;
}
......@@ -222,7 +221,7 @@ public class ServiceLogic<T, K> {
ObjectNode objNode = (ObjectNode) service;
FilterComponent docHasMrId = new FilterComponent("main_resource_id", "=", objNode.get("main_resource_id").asText());
List<T> connectedDocs = changeLogic.doGetMany((Class<T>) Document.class,
null, null, Arrays.asList(docHasMrId), null, null, authInfo);
null, null, Arrays.asList(docHasMrId), null, null);
FileHelper.readDocumentFileToContent(connectedDocs, Document.class);
Map<String, List<T>> fieldNameMapDataObject = extractItemsByFieldName(connectedDocs, Document.class);
......@@ -238,7 +237,7 @@ public class ServiceLogic<T, K> {
ObjectNode objNode = (ObjectNode) dataObject;
FilterComponent docHasDataId = new FilterComponent("data_object_id", "=", objNode.get("data_object_id").asText());
List<T> connectedDocs = changeLogic.doGetMany((Class<T>) Document.class,
null, null, Arrays.asList(docHasDataId), null, null, authInfo);
null, null, Arrays.asList(docHasDataId), null, null);
FileHelper.readDocumentFileToContent(connectedDocs, Document.class);
Map<String, List<T>> fieldNameMapDataObject = extractItemsByFieldName(connectedDocs, Document.class);
......@@ -316,7 +315,7 @@ public class ServiceLogic<T, K> {
Validator.jsonCantBeEmpty(json);
Class<T> classRepresentingTable = Finals.getClassRepresentingTable(tableName);
List<K> createdKeys = changeLogic.doCreate(json, classRepresentingTable, user);
List<K> createdKeys = changeLogic.doCreate(json, classRepresentingTable);
return Response.ok(createdKeys).build();
......@@ -356,7 +355,7 @@ public class ServiceLogic<T, K> {
Map<String, Integer> updatedResult = null;
Class<T> classRepresentingTable = Finals.getClassRepresentingTable(tableName);
updatedResult = changeLogic.doUpdate(json, classRepresentingTable, id, Finals.NAME, user);
updatedResult = changeLogic.doUpdate(json, classRepresentingTable, id, Finals.NAME);
LOG.info("" + updatedResult);
return Response.ok(updatedResult).build();
......@@ -390,7 +389,7 @@ public class ServiceLogic<T, K> {
Validator.unknownTableRequested(tableName);
Validator.tableCantBeModified(tableName);
Map<String, Integer> deletedResult = changeLogic.doDelete(tableName, id, authInfo);
Map<String, Integer> deletedResult = changeLogic.doDelete(tableName, id);
return Response.ok(deletedResult).build();
} catch (RihaRestException e) {
......@@ -478,10 +477,10 @@ public class ServiceLogic<T, K> {
QueryHolder queryHolder = new QueryHolder(operation, path, token, limit, offset, filterComponents, sort, fields);
if (StringHelper.areEqual(operation, Finals.GET)) {
Object result = changeLogic.doGet(queryHolder, user);
Object result = changeLogic.doGet(queryHolder);
return Response.ok(result).build();
} else if (StringHelper.areEqual(operation, Finals.COUNT)) {
Object result = changeLogic.doCount(queryHolder, user);
Object result = changeLogic.doCount(queryHolder);
return Response.ok(result).build();
}
return Response.ok().build();
......@@ -582,7 +581,7 @@ public class ServiceLogic<T, K> {
if (StringHelper.areEqual(queryHolder.getOp(), Finals.GET)) {
Object result = changeLogic.doGet(queryHolder, user);
Object result = changeLogic.doGet(queryHolder);
return Response.ok(result).build();
} else if (StringHelper.areEqual(queryHolder.getOp(), Finals.POST)) {
......@@ -590,7 +589,7 @@ public class ServiceLogic<T, K> {
String[] reqPars1 = {"data" };
Validator.cantHaveMissingReqParsInJson(reqPars1, json);
List<K> createdKeys = changeLogic.doCreate(queryHolder.getData().toString(), classRepresentingTable, user);
List<K> createdKeys = changeLogic.doCreate(queryHolder.getData().toString(), classRepresentingTable);
return Response.ok(createdKeys).build();
} else if (StringHelper.areEqual(queryHolder.getOp(), Finals.PUT)) {
......@@ -598,17 +597,17 @@ public class ServiceLogic<T, K> {
String[] reqPars1 = {"data" };
Validator.cantHaveMissingReqParsInJson(reqPars1, json);
Map<String, Integer> updateResult = changeLogic.doUpdate(queryHolder, user);
Map<String, Integer> updateResult = changeLogic.doUpdate(queryHolder);
return Response.ok(updateResult).build();
} else if (StringHelper.areEqual(queryHolder.getOp(), Finals.DELETE)) {
Map<String, Integer> deletedResult = changeLogic.doDelete(queryHolder, user);
Map<String, Integer> deletedResult = changeLogic.doDelete(queryHolder);
return Response.ok(deletedResult).build();
} else if (StringHelper.areEqual(queryHolder.getOp(), Finals.COUNT)) {
Map<String, Integer> resultCount = changeLogic.doCount(queryHolder, user);
Map<String, Integer> resultCount = changeLogic.doCount(queryHolder);
return Response.ok(resultCount).build();
} else if (StringHelper.areEqual(queryHolder.getOp(), Finals.NEW_VERSION)) {
......@@ -658,7 +657,7 @@ public class ServiceLogic<T, K> {
// Validator.tableCantBeUpdated(pathHolder.tableName);
}
Map<String, Map<String, String>> names = changeLogic.doGetNames(queryHolder, user);
Map<String, Map<String, String>> names = changeLogic.doGetNames(queryHolder);
return Response.ok(names).build();
}
......
......@@ -15,7 +15,6 @@ import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import ee.eesti.riha.rest.auth.AuthInfo;
import ee.eesti.riha.rest.dao.GenericDAO;
import ee.eesti.riha.rest.dao.KindRepository;
import ee.eesti.riha.rest.dao.UtilitiesDAO;
......@@ -56,12 +55,10 @@ public class TableEntryCreateLogic<T> {
*
* @param json array containting elements to be parsed
* @param classRepresentingTable given object type/table to parse every json element
* @param user the user
* @return list containing objects that hold json element parsed with parse result
* @throws RihaRestException the riha rest exception
*/
public List<JsonParseData> parseEveryJsonInArrayToObjOfDestinationClass(String json, Class<T> classRepresentingTable,
Object user) throws RihaRestException {
public List<JsonParseData> parseEveryJsonInArrayToObjOfDestinationClass(String json, Class<T> classRepresentingTable) throws RihaRestException {
List<JsonParseData> resultingParseResults = new ArrayList<>();
......@@ -70,7 +67,7 @@ public class TableEntryCreateLogic<T> {
List<JsonObject> fromJson = JsonHelper.GSON.fromJson(json, new TypeToken<List<JsonObject>>() {
}.getType());
for (JsonObject t : fromJson) {
T item = jsonToObjOfType(t.toString(), classRepresentingTable, user);
T item = jsonToObjOfType(t.toString(), classRepresentingTable);
resultingParseResults.add(new JsonParseData(t.toString(), item));
......@@ -92,11 +89,10 @@ public class TableEntryCreateLogic<T> {
*
* @param json the json
* @param classRepresentingTable the class representing table
* @param user the user
* @return the t
* @throws RihaRestException the riha rest exception
*/
public T jsonToObjOfType(String json, Class<T> classRepresentingTable, Object user) throws RihaRestException {
public T jsonToObjOfType(String json, Class<T> classRepresentingTable) throws RihaRestException {
T fromJson = null;
......@@ -107,9 +103,9 @@ public class TableEntryCreateLogic<T> {
// expect json_content and from json_content table entry will be
// created
if (classRepresentingTable == Comment.class) {
fromJson = fromJsonContentToObjForComment(json, classRepresentingTable, user);
fromJson = fromJsonContentToObjForComment(json, classRepresentingTable);
} else {
fromJson = fromJsonContentToObj(json, classRepresentingTable, user);
fromJson = fromJsonContentToObj(json, classRepresentingTable);
}
}
......@@ -133,10 +129,9 @@ public class TableEntryCreateLogic<T> {
*
* @param json the json
* @param classRepresentingTable class representing json content based table
* @param user the user
* @return the t
*/
public T fromJsonContentToObj(String json, Class<T> classRepresentingTable, Object user) {
public T fromJsonContentToObj(String json, Class<T> classRepresentingTable) {
// expect json_content
JsonObject jsonContent = JsonHelper.getFromJson(json);
......@@ -174,20 +169,19 @@ public class TableEntryCreateLogic<T> {
jsonContent.addProperty("uri", generatedUri);
}
return fromJsonToObjHelper(jsonContent, pkId, classRepresentingTable, user);
return fromJsonToObjHelper(jsonContent, pkId, classRepresentingTable);
}
/**
* Like {@link #fromJsonContentToObj(String, Class, Object)} but is special for Comment to use kind instead of
* Like {@link #fromJsonContentToObj(String, Class)} but is special for Comment to use kind instead of
* kind_id, because Comment does not have kind_id field at this point.
*
* @param json the json
* @param classRepresentingTable the class representing table
* @param user the user
* @return the t
*/
public T fromJsonContentToObjForComment(String json, Class<T> classRepresentingTable, Object user) {
public T fromJsonContentToObjForComment(String json, Class<T> classRepresentingTable) {
// expect json_content
JsonObject jsonContent = JsonHelper.getFromJson(json);
......@@ -206,7 +200,7 @@ public class TableEntryCreateLogic<T> {
jsonContent.addProperty("uri", generatedUri);
}
return fromJsonToObjHelper(jsonContent, pkId, classRepresentingTable, user);
return fromJsonToObjHelper(jsonContent, pkId, classRepresentingTable);
}
......@@ -214,26 +208,19 @@ public class TableEntryCreateLogic<T> {
* Helper method for code reuse.
*
* @param jsonContent the json content
* @param pk_id the pk_id
* @param pkId the pk_id
* @param classRepresentingTable the class representing table
* @param user the user
* @return the t
*/
private T fromJsonToObjHelper(JsonObject jsonContent, Integer pkId, Class<T> classRepresentingTable, Object user) {
private T fromJsonToObjHelper(JsonObject jsonContent, Integer pkId, Class<T> classRepresentingTable) {
T constructedJsonObj;
Gson gson = JsonHelper.GSON;
jsonContent.addProperty("creator", ((AuthInfo) user).getUser_code());
Date dt = new Date();
String dtJsonFormat = DateHelper.FORMATTER.format(dt);
LOG.info(dtJsonFormat);
jsonContent.addProperty("creation_date", dtJsonFormat);
if (!jsonContent.has("owner") || jsonContent.get("owner").isJsonNull()) {
jsonContent.addProperty("owner", ((AuthInfo) user).getOrg_code());
}
// save primary key to json_content as well
String pkFieldName = createPKFieldName(classRepresentingTable);
jsonContent.addProperty(pkFieldName, pkId);
......@@ -263,15 +250,14 @@ public class TableEntryCreateLogic<T> {
}
/**
* Like {@link #fromJsonContentToObj(String, Class, Object)}, but keeps existing information (e.g creation_date).
* Like {@link #fromJsonContentToObj(String, Class)}, but keeps existing information (e.g creation_date).
* Needed for changeLogic.doNewVersion()
*
* @param json the json
* @param classRepresentingTable the class representing table
* @param user the user
* @return the t
*/
public T fromJsonContentToObjKeepExisting(String json, Class<T> classRepresentingTable, Object user)
public T fromJsonContentToObjKeepExisting(String json, Class<T> classRepresentingTable)
throws RihaRestException {
// expect json_content
......
......@@ -49,7 +49,7 @@ public class FileServiceImpl implements FileService {
try {
AuthInfo user = TokenValidator.isTokenOk(token, tokenStore);
String fields = "[\"document_id\", \"filename\"]";
ObjectNode jsonObject = (ObjectNode) changeLogic.doGet(Document.class, documentId, fields, user);
ObjectNode jsonObject = (ObjectNode) changeLogic.doGet(Document.class, documentId, fields);
return getFileLogic(documentId, jsonObject, token);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment