[Fix] Remove version of parsed files in inspector
This commit is contained in:
parent
ab0930eec8
commit
ba115b70c4
|
@ -21,9 +21,6 @@ import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import li.strolch.agent.api.ElementMap;
|
import li.strolch.agent.api.ElementMap;
|
||||||
import li.strolch.agent.api.StrolchAgent;
|
import li.strolch.agent.api.StrolchAgent;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
|
@ -37,6 +34,8 @@ import li.strolch.persistence.api.StrolchDao;
|
||||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.runtime.StrolchConstants;
|
import li.strolch.runtime.StrolchConstants;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -228,6 +227,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
* {@link CachedRealm}
|
* {@link CachedRealm}
|
||||||
*
|
*
|
||||||
* @param element
|
* @param element
|
||||||
|
* the element to insert
|
||||||
*/
|
*/
|
||||||
synchronized void insert(T element) {
|
synchronized void insert(T element) {
|
||||||
getCachedDao().save(element);
|
getCachedDao().save(element);
|
||||||
|
@ -235,7 +235,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void add(StrolchTransaction tx, T element) {
|
public synchronized void add(StrolchTransaction tx, T element) {
|
||||||
if (realm.isVersioningEnabled()) {
|
if (this.realm.isVersioningEnabled()) {
|
||||||
int latestVersion = getLatestVersionFor(tx, element.getType(), element.getId());
|
int latestVersion = getLatestVersionFor(tx, element.getType(), element.getId());
|
||||||
Version.setInitialVersionFor(element, latestVersion, tx.getCertificate().getUsername());
|
Version.setInitialVersionFor(element, latestVersion, tx.getCertificate().getUsername());
|
||||||
} else {
|
} else {
|
||||||
|
@ -251,7 +251,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
@Override
|
@Override
|
||||||
public synchronized void addAll(StrolchTransaction tx, List<T> elements) {
|
public synchronized void addAll(StrolchTransaction tx, List<T> elements) {
|
||||||
for (T element : elements) {
|
for (T element : elements) {
|
||||||
if (realm.isVersioningEnabled()) {
|
if (this.realm.isVersioningEnabled()) {
|
||||||
int latestVersion = getLatestVersionFor(tx, element.getType(), element.getId());
|
int latestVersion = getLatestVersionFor(tx, element.getType(), element.getId());
|
||||||
Version.setInitialVersionFor(element, latestVersion, tx.getCertificate().getUsername());
|
Version.setInitialVersionFor(element, latestVersion, tx.getCertificate().getUsername());
|
||||||
} else {
|
} else {
|
||||||
|
@ -267,10 +267,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void update(StrolchTransaction tx, T element) {
|
public synchronized void update(StrolchTransaction tx, T element) {
|
||||||
if (realm.isVersioningEnabled())
|
updateVersion(tx, element);
|
||||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), false);
|
|
||||||
else
|
|
||||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
|
||||||
|
|
||||||
// first perform cached change
|
// first perform cached change
|
||||||
getCachedDao().update(element);
|
getCachedDao().update(element);
|
||||||
|
@ -281,10 +278,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
@Override
|
@Override
|
||||||
public synchronized void updateAll(StrolchTransaction tx, List<T> elements) {
|
public synchronized void updateAll(StrolchTransaction tx, List<T> elements) {
|
||||||
for (T t : elements) {
|
for (T t : elements) {
|
||||||
if (realm.isVersioningEnabled())
|
updateVersion(tx, t);
|
||||||
Version.updateVersionFor(t, tx.getCertificate().getUsername(), false);
|
|
||||||
else
|
|
||||||
Version.setInitialVersionFor(t, -1, tx.getCertificate().getUsername());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// first perform cached change
|
// first perform cached change
|
||||||
|
@ -295,10 +289,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void remove(StrolchTransaction tx, T element) {
|
public synchronized void remove(StrolchTransaction tx, T element) {
|
||||||
if (realm.isVersioningEnabled())
|
updateVersion(tx, element);
|
||||||
Version.updateVersionFor(element, tx.getCertificate().getUsername(), true);
|
|
||||||
else
|
|
||||||
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
|
||||||
|
|
||||||
if (this.realm.isVersioningEnabled()) {
|
if (this.realm.isVersioningEnabled()) {
|
||||||
|
|
||||||
|
@ -319,10 +310,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
@Override
|
@Override
|
||||||
public synchronized void removeAll(StrolchTransaction tx, List<T> elements) {
|
public synchronized void removeAll(StrolchTransaction tx, List<T> elements) {
|
||||||
for (T t : elements) {
|
for (T t : elements) {
|
||||||
if (realm.isVersioningEnabled())
|
updateVersion(tx, t);
|
||||||
Version.updateVersionFor(t, tx.getCertificate().getUsername(), true);
|
|
||||||
else
|
|
||||||
Version.setInitialVersionFor(t, -1, tx.getCertificate().getUsername());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.realm.isVersioningEnabled()) {
|
if (this.realm.isVersioningEnabled()) {
|
||||||
|
@ -341,6 +329,14 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateVersion(StrolchTransaction tx, T element) {
|
||||||
|
if (this.realm.isVersioningEnabled()) {
|
||||||
|
Version.updateVersionFor(element, tx.getCertificate().getUsername(), false);
|
||||||
|
} else {
|
||||||
|
Version.setInitialVersionFor(element, -1, tx.getCertificate().getUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized long removeAll(StrolchTransaction tx) {
|
public synchronized long removeAll(StrolchTransaction tx) {
|
||||||
// first perform cached change
|
// first perform cached change
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -29,7 +29,7 @@ import li.strolch.model.activity.Activity;
|
||||||
/**
|
/**
|
||||||
* {@link StrolchElementListener} to store the {@link StrolchRootElement} in {@link Map} objects when parsing an object
|
* {@link StrolchElementListener} to store the {@link StrolchRootElement} in {@link Map} objects when parsing an object
|
||||||
* model from an external source
|
* model from an external source
|
||||||
*
|
*
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class SimpleStrolchElementListener implements StrolchElementListener {
|
public class SimpleStrolchElementListener implements StrolchElementListener {
|
||||||
|
|
|
@ -70,6 +70,7 @@ import li.strolch.service.UpdateActivityService.UpdateActivityArg;
|
||||||
import li.strolch.service.UpdateOrderService.UpdateOrderArg;
|
import li.strolch.service.UpdateOrderService.UpdateOrderArg;
|
||||||
import li.strolch.service.UpdateResourceService.UpdateResourceArg;
|
import li.strolch.service.UpdateResourceService.UpdateResourceArg;
|
||||||
import li.strolch.service.api.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
import li.strolch.utils.dbc.DBC;
|
||||||
import li.strolch.utils.helper.StringHelper;
|
import li.strolch.utils.helper.StringHelper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -723,6 +724,7 @@ public class Inspector {
|
||||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||||
|
|
||||||
Resource resource = parseResourceFromXml(type, data);
|
Resource resource = parseResourceFromXml(type, data);
|
||||||
|
DBC.INTERIM.assertEquals("Posted id must be same as request!", id, resource.getId());
|
||||||
|
|
||||||
UpdateResourceService svc = new UpdateResourceService();
|
UpdateResourceService svc = new UpdateResourceService();
|
||||||
UpdateResourceArg arg = new UpdateResourceArg();
|
UpdateResourceArg arg = new UpdateResourceArg();
|
||||||
|
@ -772,6 +774,8 @@ public class Inspector {
|
||||||
arg.refreshUnknownVersion = true;
|
arg.refreshUnknownVersion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted id must be same as request!", id, resource.getId());
|
||||||
|
|
||||||
// prepare argument
|
// prepare argument
|
||||||
arg.resource = resource;
|
arg.resource = resource;
|
||||||
arg.realm = realm;
|
arg.realm = realm;
|
||||||
|
@ -798,6 +802,7 @@ public class Inspector {
|
||||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||||
|
|
||||||
Order order = parseOrderFromXml(type, data);
|
Order order = parseOrderFromXml(type, data);
|
||||||
|
DBC.INTERIM.assertEquals("Posted id must be same as request!", id, order.getId());
|
||||||
|
|
||||||
UpdateOrderService svc = new UpdateOrderService();
|
UpdateOrderService svc = new UpdateOrderService();
|
||||||
UpdateOrderArg arg = new UpdateOrderArg();
|
UpdateOrderArg arg = new UpdateOrderArg();
|
||||||
|
@ -847,6 +852,8 @@ public class Inspector {
|
||||||
arg.refreshUnknownVersion = true;
|
arg.refreshUnknownVersion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted id must be same as request!", id, order.getId());
|
||||||
|
|
||||||
// prepare argument
|
// prepare argument
|
||||||
arg.order = order;
|
arg.order = order;
|
||||||
arg.realm = realm;
|
arg.realm = realm;
|
||||||
|
@ -873,6 +880,7 @@ public class Inspector {
|
||||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||||
|
|
||||||
Activity activity = parseActivityFromXml(type, data);
|
Activity activity = parseActivityFromXml(type, data);
|
||||||
|
DBC.INTERIM.assertEquals("Posted id must be same as request!", id, activity.getId());
|
||||||
|
|
||||||
UpdateActivityService svc = new UpdateActivityService();
|
UpdateActivityService svc = new UpdateActivityService();
|
||||||
UpdateActivityArg arg = new UpdateActivityArg();
|
UpdateActivityArg arg = new UpdateActivityArg();
|
||||||
|
@ -922,6 +930,8 @@ public class Inspector {
|
||||||
arg.refreshUnknownVersion = true;
|
arg.refreshUnknownVersion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted id must be same as request!", id, activity.getId());
|
||||||
|
|
||||||
// prepare argument
|
// prepare argument
|
||||||
arg.activity = activity;
|
arg.activity = activity;
|
||||||
arg.realm = realm;
|
arg.realm = realm;
|
||||||
|
@ -1148,7 +1158,7 @@ public class Inspector {
|
||||||
@Produces(MediaType.APPLICATION_XML)
|
@Produces(MediaType.APPLICATION_XML)
|
||||||
@Consumes(MediaType.APPLICATION_XML)
|
@Consumes(MediaType.APPLICATION_XML)
|
||||||
@Path("{realm}/activities")
|
@Path("{realm}/activities")
|
||||||
public Response addActivitiyAsXml(@Context HttpServletRequest request, @PathParam("realm") String realm,
|
public Response addActivityAsXml(@Context HttpServletRequest request, @PathParam("realm") String realm,
|
||||||
String data) {
|
String data) {
|
||||||
|
|
||||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||||
|
@ -1173,7 +1183,7 @@ public class Inspector {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Path("{realm}/activities")
|
@Path("{realm}/activities")
|
||||||
public Response addActivitiyAsJson(@Context HttpServletRequest request, @PathParam("realm") String realm,
|
public Response addActivityAsJson(@Context HttpServletRequest request, @PathParam("realm") String realm,
|
||||||
String data) {
|
String data) {
|
||||||
|
|
||||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||||
|
@ -1201,7 +1211,7 @@ public class Inspector {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Path("{realm}/activities/{type}")
|
@Path("{realm}/activities/{type}")
|
||||||
public Response addActivitiyAsJsonFlat(@Context HttpServletRequest request, @PathParam("realm") String realm,
|
public Response addActivityAsJsonFlat(@Context HttpServletRequest request, @PathParam("realm") String realm,
|
||||||
@PathParam("type") String type, @QueryParam("flat") String flatS, String data) {
|
@PathParam("type") String type, @QueryParam("flat") String flatS, String data) {
|
||||||
|
|
||||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||||
|
@ -1295,6 +1305,9 @@ public class Inspector {
|
||||||
""));
|
""));
|
||||||
|
|
||||||
resource = listener.getResources().get(0);
|
resource = listener.getResources().get(0);
|
||||||
|
resource.setVersion(null);
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted type must be same as request!", type, resource.getType());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new StrolchPersistenceException(
|
throw new StrolchPersistenceException(
|
||||||
|
@ -1322,6 +1335,9 @@ public class Inspector {
|
||||||
""));
|
""));
|
||||||
|
|
||||||
order = listener.getOrders().get(0);
|
order = listener.getOrders().get(0);
|
||||||
|
order.setVersion(null);
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted type must be same as request!", type, order.getType());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new StrolchPersistenceException(
|
throw new StrolchPersistenceException(
|
||||||
|
@ -1351,6 +1367,9 @@ public class Inspector {
|
||||||
""));
|
""));
|
||||||
|
|
||||||
activity = listener.getActivities().get(0);
|
activity = listener.getActivities().get(0);
|
||||||
|
activity.setVersion(null);
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted type must be same as request!", type, activity.getType());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new StrolchPersistenceException(
|
throw new StrolchPersistenceException(
|
||||||
|
@ -1380,6 +1399,9 @@ public class Inspector {
|
||||||
// parse from complete JSON
|
// parse from complete JSON
|
||||||
ResourceFromJsonVisitor visitor = new ResourceFromJsonVisitor();
|
ResourceFromJsonVisitor visitor = new ResourceFromJsonVisitor();
|
||||||
resource = visitor.visit(jsonObject);
|
resource = visitor.visit(jsonObject);
|
||||||
|
resource.setVersion(null);
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted type must be same as request!", type, resource.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
return resource;
|
return resource;
|
||||||
|
@ -1404,6 +1426,9 @@ public class Inspector {
|
||||||
// parse from complete JSON
|
// parse from complete JSON
|
||||||
OrderFromJsonVisitor visitor = new OrderFromJsonVisitor();
|
OrderFromJsonVisitor visitor = new OrderFromJsonVisitor();
|
||||||
order = visitor.visit(jsonObject);
|
order = visitor.visit(jsonObject);
|
||||||
|
order.setVersion(null);
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted type must be same as request!", type, order.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
return order;
|
return order;
|
||||||
|
@ -1428,6 +1453,9 @@ public class Inspector {
|
||||||
// parse from complete JSON
|
// parse from complete JSON
|
||||||
ActivityFromJsonVisitor visitor = new ActivityFromJsonVisitor();
|
ActivityFromJsonVisitor visitor = new ActivityFromJsonVisitor();
|
||||||
activity = visitor.visit(jsonObject);
|
activity = visitor.visit(jsonObject);
|
||||||
|
activity.setVersion(null);
|
||||||
|
|
||||||
|
DBC.INTERIM.assertEquals("Posted type must be same as request!", type, activity.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
return activity;
|
return activity;
|
||||||
|
|
Loading…
Reference in New Issue