Commit cf694178 authored by Valentin Suhnjov's avatar Valentin Suhnjov

RIHAKB-130. Remove user and authentication from NewVersionLogic

parent bef967c6
......@@ -121,7 +121,7 @@ public class ImportLogic {
// 1. create new version from Main_resource in database
String newVersion = importJson.get("version").getAsString();
newVersionLogic.doNewVersion(newVersion, uri, user);
newVersionLogic.doNewVersion(newVersion, uri);
// 2. update new version of Main_resource with values from importJson
// main_resource_id stays the same, copy will have new id
......
......@@ -16,7 +16,6 @@ import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.JsonObject;
import ee.eesti.riha.rest.auth.AuthInfo;
import ee.eesti.riha.rest.dao.GenericDAO;
import ee.eesti.riha.rest.dao.SecureApiGenericDAO;
import ee.eesti.riha.rest.dao.util.FilterComponent;
......@@ -63,13 +62,12 @@ public class NewVersionLogic<T, K> {
* Unmodifiability is checked elsewhere (by end_date).
*
* @param queryHolder the query holder
* @param user AuthInfo user
* @return new version as ObjectNode
* @throws RihaRestException the riha rest exception
* @throws ReflectiveOperationException the reflective operation exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public Object doNewVersion(QueryHolder queryHolder, Object user) throws RihaRestException,
public Object doNewVersion(QueryHolder queryHolder) throws RihaRestException,
ReflectiveOperationException, IOException {
LOG.info("doNewVersion");
// 0. extract data from queryHolder
......@@ -92,7 +90,6 @@ public class NewVersionLogic<T, K> {
String newVersion = query.get("new_version").getAsString();
String uri = query.get("uri").getAsString();
String userId = ((AuthInfo) user).getUser_code();
// 1. find old by uri, sort by start_date (to get current)
// sort by creation_date instead !! (start_date may be null)
......@@ -124,7 +121,6 @@ public class NewVersionLogic<T, K> {
String dateJson = DateHelper.FORMATTER.format(new Date());
tempJson.put("end_date", dateJson);
tempJson.put("modified_date", dateJson);
tempJson.put("modifier", userId);
// remove kind, because kind_id should be used instead of kind in server
tempJson.remove("kind");
......@@ -137,8 +133,6 @@ public class NewVersionLogic<T, K> {
// 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);
ObjectNode oldJson = (ObjectNode) temp;
......@@ -147,8 +141,6 @@ public class NewVersionLogic<T, K> {
oldJson.put("start_date", dateJson);
// 6. set new created, modified to old
oldJson.put("creator", userId);
oldJson.put("modifier", userId);
oldJson.put("creation_date", dateJson);
oldJson.put("modified_date", dateJson);
// when creating new version, then end_date will be null
......@@ -168,19 +160,19 @@ public class NewVersionLogic<T, K> {
// temp = doGet(classRepresentingTable, id, null, null);
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);
doNewVersionDocument((Class<T>) Document.class, id, archivedKeys.get(0), dateJson);
doNewVersionData_object((Class<T>) Data_object.class, id, archivedKeys.get(0), dateJson);
return temp;
}
/**
* Helper method to call {@link #doNewVersion(QueryHolder, Object)}. This method only builds the queryHolder needed,
* Helper method to call {@link #doNewVersion(QueryHolder)}. This method only builds the queryHolder needed,
* to ease access from other classes.
*
* @see #doNewVersion(QueryHolder, Object)
* @see #doNewVersion(QueryHolder)
*/
public Object doNewVersion(String newVersion, String uri, AuthInfo user) throws RihaRestException,
public Object doNewVersion(String newVersion, String uri) throws RihaRestException,
ReflectiveOperationException, IOException {
LOG.info("doNewVersion construct queryHolder");
......@@ -191,32 +183,32 @@ public class NewVersionLogic<T, K> {
// op is not needed
QueryHolder queryHolder = QueryHolder.create(JsonHelper.GSON, queryJson.toString());
return doNewVersion(queryHolder, user);
return doNewVersion(queryHolder);
}
private void doNewVersionDocument(Class<T> clazz, int currentMain_resourceId, int archivedMain_resourceId,
String dateJson, AuthInfo user) throws RihaRestException {
String dateJson) throws RihaRestException {
LOG.info("doNewVersionDocument currentMainResourceId " + currentMain_resourceId
+ " archivedMainResourceId " + archivedMain_resourceId);
FilterComponent filterByMR = new FilterComponent("main_resource_id", "=", "" + currentMain_resourceId);
doNewVersionDocumentHelper(clazz, filterByMR, archivedMain_resourceId, "main_resource_id", dateJson, user);
doNewVersionDocumentHelper(clazz, filterByMR, archivedMain_resourceId, "main_resource_id", dateJson);
}
private void doNewVersionDocumentThroughData_object(Class<T> clazz, int currentData_objectId,
int archivedData_objectId, String dateJson, AuthInfo user) throws RihaRestException {
int archivedData_objectId, String dateJson) throws RihaRestException {
FilterComponent filterByData_object = new FilterComponent("data_object_id", "=", "" + currentData_objectId);
doNewVersionDocumentHelper(clazz, filterByData_object, archivedData_objectId, "data_object_id", dateJson, user);
doNewVersionDocumentHelper(clazz, filterByData_object, archivedData_objectId, "data_object_id", dateJson);
}
private void doNewVersionDocumentHelper(Class<T> clazz, FilterComponent filterById, int archivedId, String idField,
String dateJson, AuthInfo user) throws RihaRestException {
String dateJson) throws RihaRestException {
// find all connected Documents
// List<ObjectNode> actually
......@@ -241,10 +233,6 @@ public class NewVersionLogic<T, K> {
docJson.remove(pkField);
docJson.put(idField, archivedId);
// can't add end_date here, because can't update object which has end_date set with SecureApiGenericDAO
// docJson.put("end_date", dateJson);
docJson.put("modified_date", dateJson);
docJson.put("modifier", user.getUser_code());
// remove kind
docJson.remove("kind");
......@@ -269,7 +257,6 @@ public class NewVersionLogic<T, K> {
LOG.info("Original doc, that becomes current: " + docJson);
docJson.put("start_date", dateJson);
docJson.put("modified_date", dateJson);
docJson.put("modifier", user.getUser_code());
// remove kind
docJson.remove("kind");
// when creating new version, then end_date will be null
......@@ -319,7 +306,7 @@ public class NewVersionLogic<T, K> {
}
private void doNewVersionData_object(Class<T> clazz, int currentMain_resourceId, int archivedMain_resourceId,
String dateJson, AuthInfo user) throws RihaRestException {
String dateJson) throws RihaRestException {
// find all connected Data_objects
FilterComponent filterByMR = new FilterComponent("main_resource_id", "=", "" + currentMain_resourceId);
// List<ObjectNode> actually
......@@ -342,7 +329,6 @@ public class NewVersionLogic<T, K> {
dataJson.put("main_resource_id", archivedMain_resourceId);
dataJson.put("end_date", dateJson);
dataJson.put("modified_date", dateJson);
dataJson.put("modifier", user.getUser_code());
// remove kind
dataJson.remove("kind");
......@@ -362,7 +348,6 @@ public class NewVersionLogic<T, K> {
ObjectNode dataJson = (ObjectNode) connectedData;
dataJson.put("start_date", dateJson);
dataJson.put("modified_date", dateJson);
dataJson.put("modifier", user.getUser_code());
// remove kind
dataJson.remove("kind");
// when creating new version, then end_date will be null
......@@ -387,7 +372,7 @@ public class NewVersionLogic<T, K> {
}
for (int[] ids : uriToDataIdMap.values()) {
doNewVersionDocumentThroughData_object((Class<T>) Document.class, ids[0], ids[1], dateJson, user);
doNewVersionDocumentThroughData_object((Class<T>) Document.class, ids[0], ids[1], dateJson);
}
}
......
......@@ -300,10 +300,9 @@ public class ServiceLogic<T, K> {
*
* @param json the json
* @param tableName the table name
* @param user the user
* @return the response
*/
public Response create(String json, String tableName, Object user) {
public Response create(String json, String tableName) {
LOG.info("create API called");
......@@ -338,10 +337,9 @@ public class ServiceLogic<T, K> {
* @param json the json
* @param tableName the table name
* @param id the id
* @param user the user
* @return the response
*/
public Response update(String json, String tableName, Integer id, Object user) {
public Response update(String json, String tableName, Integer id) {
LOG.info("update API called");
......@@ -380,7 +378,7 @@ public class ServiceLogic<T, K> {
* @param id the id
* @return the response
*/
public Response delete(String tableName, Integer id, AuthInfo authInfo) {
public Response delete(String tableName, Integer id) {
LOG.info("delete API called");
......@@ -438,21 +436,6 @@ public class ServiceLogic<T, K> {
ErrorCodes.INPUT_URL_OP_VALUE_UNKNOWN_OR_NOTSUITABLE,
ErrorCodes.INPUT_URL_OP_VALUE_UNKNOWN_OR_NOTSUITABLE_MSG);
// if doesn't throw then OK
// TokenValidator.isTokenOk(token);
// Object user = TokenValidator.isTokenOk(token, authServiceProvider.get());
// no need to currently authenticate for GET requests
// AuthInfo user = TokenValidator.isTokenOk(token, tokenStore);
// allow to read if token not given
AuthInfo user = null;
if (!StringUtils.isEmpty(token)) {
user = TokenValidator.isTokenOk(token, tokenStore);
} else {
user = AuthInfo.DEFAULT;
}
PathHolder pathHolder = null;
try {
pathHolder = new PathHolder(path);
......@@ -534,11 +517,6 @@ public class ServiceLogic<T, K> {
Validator.valueMustBeAllowed(Finals.POST_CGI_ALLOWED_VALUES, queryHolder.getOp(),
ErrorCodes.INPUT_JSON_OP_VALUE_UNKNOWN, ErrorCodes.INPUT_JSON_OP_VALUE_UNKNOWN_MSG);
// if doesn't throw then OK
// TokenValidator.isTokenOk(queryHolder.getToken());
// Object user = TokenValidator.isTokenOk(
// queryHolder.getToken(), authServiceProvider.get());
AuthInfo user = null;
if (!Finals.READ_ALLOWED_VALUES.contains(queryHolder.getOp())) {
// no need to currently authenticate for GET requests
......@@ -612,8 +590,7 @@ public class ServiceLogic<T, K> {
} else if (StringHelper.areEqual(queryHolder.getOp(), Finals.NEW_VERSION)) {
// Object result = changeLogic.doNewVersion(queryHolder, user);
Object result = newVersionLogic.doNewVersion(queryHolder, user);
Object result = newVersionLogic.doNewVersion(queryHolder);
return Response.ok(result).build();
}
......@@ -643,19 +620,6 @@ public class ServiceLogic<T, K> {
private Response specialCGI(QueryHolder queryHolder) throws RihaRestException {
Validator.valueMustBeAllowed(Finals.POST_CGI_ALLOWED_VALUES, queryHolder.getOp(),
ErrorCodes.INPUT_JSON_OP_VALUE_UNKNOWN, ErrorCodes.INPUT_JSON_OP_VALUE_UNKNOWN_MSG);
// if doesn't throw then OK
// Object user = TokenValidator.isTokenOk(
// queryHolder.getToken(), authServiceProvider.get());
// AuthInfo user = TokenValidator.isTokenOk(queryHolder.getToken(), tokenStore);
AuthInfo user = null;
if (!Finals.READ_ALLOWED_VALUES.contains(queryHolder.getOp())) {
// no need to currently authenticate for GET requests
user = TokenValidator.isTokenOk(queryHolder.getToken(), tokenStore);
// may be needed in future
// Validator.tableCantBeUpdated(pathHolder.tableName);
}
Map<String, Map<String, String>> names = changeLogic.doGetNames(queryHolder);
......
......@@ -124,7 +124,7 @@ public class ApiClassicServiceImpl<T, K> implements ApiClassicService {
return (new Command() {
@Override
public Response commandMethod(Object user) {
return serviceLogic.create(json, tableName, user);
return serviceLogic.create(json, tableName);
}
}).doIfHeadersOk();
......@@ -143,7 +143,7 @@ public class ApiClassicServiceImpl<T, K> implements ApiClassicService {
return (new Command() {
@Override
public Response commandMethod(Object user) {
return serviceLogic.update(json, tableName, id, user);
return serviceLogic.update(json, tableName, id);
}
}).doIfHeadersOk();
......@@ -162,7 +162,7 @@ public class ApiClassicServiceImpl<T, K> implements ApiClassicService {
return (new Command() {
@Override
public Response commandMethod(Object user) {
return serviceLogic.delete(tableName, id, (AuthInfo) user);
return serviceLogic.delete(tableName, id);
}
}).doIfHeadersOk();
......
......@@ -6,14 +6,12 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -38,14 +36,11 @@ import ee.eesti.riha.rest.logic.Finals;
import ee.eesti.riha.rest.logic.NewVersionLogic;
import ee.eesti.riha.rest.logic.URI;
import ee.eesti.riha.rest.logic.util.JsonHelper;
import ee.eesti.riha.rest.model.BaseModel;
import ee.eesti.riha.rest.model.Data_object;
import ee.eesti.riha.rest.model.Document;
import ee.eesti.riha.rest.model.Main_resource;
import ee.eesti.riha.rest.model.readonly.Kind;
import ee.eesti.riha.rest.service.ApiClassicService;
import ee.eesti.riha.rest.service.ApiImportService;
import ee.eesti.riha.rest.service.ApiTableService;
@RunWith(MyTestRunner.class)
@ContextConfiguration("classpath*: **/integration-test-applicationContext.xml")
......@@ -368,7 +363,7 @@ public class TestApiImportServiceImpl {
// create new version
String newVersion = "v6";
ObjectNode newVersionObject = (ObjectNode) newVersionLogic.doNewVersion(newVersion, uri, testAuthInfo);
ObjectNode newVersionObject = (ObjectNode) newVersionLogic.doNewVersion(newVersion, uri);
// get just archived version
FilterComponent fc = new FilterComponent("uri", "=", uri);
......
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