Skip to content

Commit

Permalink
Merge branch 'feature/181-cs-cache-json' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Sep 15, 2016
2 parents b6c1135 + 446540f commit 7711e9a
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ public CidsBeanJsonDeserializer() {
//~ Methods ----------------------------------------------------------------

/**
* DOCUMENT ME!
* Helper Method creates JTS Geometry Object from WKT String with SRID.
*
* @param ewkt DOCUMENT ME!
* @param ewkt WKT String with SRID
*
* @return DOCUMENT ME!
*/
private static Geometry fromEwkt(final String ewkt) {
public static Geometry fromEwkt(final String ewkt) {
if ((ewkt == null) || ewkt.isEmpty()) {
return null;
}

final int skIndex = ewkt.indexOf(';');

final String wkt;
Expand All @@ -105,7 +109,8 @@ private static Geometry fromEwkt(final String ewkt) {
return geom;
} catch (final ParseException ex) {
if (LOG.isDebugEnabled()) {
LOG.error(ex.getMessage(), ex);
LOG.error("Cannot create geometry from WKT String '" + ewkt + ": "
+ ex.getMessage(), ex);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* ... and it just works.
*
****************************************************/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.cismet.cids.dynamics;

import com.fasterxml.jackson.core.JsonGenerationException;
Expand Down Expand Up @@ -55,7 +51,7 @@ public CidsBeanJsonSerializer() {
*
* @return DOCUMENT ME!
*/
private static String toEwkt(final Geometry geom) {
public static String toEwkt(final Geometry geom) {
if (geom == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import Sirius.server.middleware.types.StringPatternFormater;
import Sirius.server.newuser.User;
import Sirius.server.newuser.UserException;
import Sirius.server.newuser.UserGroup;

import Sirius.util.image.Image;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ private int getIntValue(final String attributeName,
*
* @return DOCUMENT ME!
*/
protected Policy createPolicy(String policyName) {
public Policy createPolicy(String policyName) {
if ((policyName == null) || policyName.isEmpty()
|| (!policyName.equalsIgnoreCase("DEFAULT")
&& !policyName.equalsIgnoreCase("STANDARD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
import Sirius.server.middleware.types.Node;
import Sirius.server.newuser.permission.Policy;

import com.vividsolutions.jts.geom.Geometry;

import org.apache.log4j.Logger;

import de.cismet.cids.dynamics.CidsBeanJsonDeserializer;
import de.cismet.cids.dynamics.CidsBeanJsonSerializer;

import de.cismet.cidsx.server.api.types.CidsNode;

/**
Expand Down Expand Up @@ -74,6 +79,8 @@ public Sirius.server.middleware.types.Node legacyCidsNodeFromRestCidsNode(
final String dynamicChildrenStatement = cidsNode.getDynamicChildren();
final boolean sqlSort = cidsNode.isClientSort();
final boolean isDynamic = cidsNode.isDynamic();
final Geometry cachedGeometry = CidsBeanJsonDeserializer.fromEwkt(cidsNode.getCachedGeometry());
final String lightweightJson = cidsNode.getLightweightJson();

final Node legacyNode;

Expand All @@ -96,8 +103,8 @@ public Sirius.server.middleware.types.Node legacyCidsNodeFromRestCidsNode(
icon,
derivePermissionsFromClass,
artificialId,
null,
null); // TODO: Check4CashedGeomAndLightweightJson
cachedGeometry,
lightweightJson);
// FIXME: creation of class tree nodes disbaled! how to determine if a cids node shall be converted to class
// tree node or simple tree node? } else if (cidsNode.getClassKey() != null &&
// !cidsNode.getClassKey().isEmpty()) { LOG.debug("node '" + cidsNode.getName() + "' (" + cidsNode.getId() +
Expand Down Expand Up @@ -158,10 +165,13 @@ public de.cismet.cidsx.server.api.types.CidsNode restCidsNodeFromLegacyCidsNode(
final int objectId;
final String classKey;
final boolean dynamic = legacyNode.isDynamic();
final String cachedGeometry;
final String lightweightJson;

if (MetaObjectNode.class.isAssignableFrom(legacyNode.getClass())) {
final MetaObjectNode metaObjectNode = (MetaObjectNode)legacyNode;
objectId = metaObjectNode.getObjectId();

if (className == null) {
LOG.warn("className == null, trying to derive class name from object node '" + name + "' (" + id + ")");
if ((metaObjectNode.getObject() != null) && (metaObjectNode.getObject().getMetaClass() != null)) {
Expand All @@ -176,12 +186,17 @@ public de.cismet.cidsx.server.api.types.CidsNode restCidsNodeFromLegacyCidsNode(
LOG.error("could not set object key of object node '" + name + "' (" + id
+ "), domain or classKey == null");
}

cachedGeometry = CidsBeanJsonSerializer.toEwkt(metaObjectNode.getCashedGeometry());
lightweightJson = metaObjectNode.getLightweightJson();
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("node '" + name + "' (" + id + ") is no meta object node -> class node or pure node");
}
objectId = -1;
objectKey = null;
cachedGeometry = null;
lightweightJson = null;
}

// cannot derive class name from meta class node since meta class node
Expand Down Expand Up @@ -213,6 +228,8 @@ public de.cismet.cidsx.server.api.types.CidsNode restCidsNodeFromLegacyCidsNode(
leaf,
dynamic,
icon,
cachedGeometry,
lightweightJson,
iconFactory,
policy,
artificialId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
* ... and it just works.
*
****************************************************/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.cismet.cidsx.server.api.types.legacy;

import Sirius.server.middleware.types.MetaClass;
Expand All @@ -20,6 +15,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.ClassUtils;
import org.apache.log4j.Logger;

Expand All @@ -39,6 +35,7 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;

import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;

Expand Down Expand Up @@ -389,9 +386,8 @@ public CidsServerSearch serverSearchInstanceFromSearchParameters(
paramClassName = searchParameterInfo.getType().getJavaType();
}

if (searchParameterInfo.isArray()) {
paramClassName += "[]";
}
/*if (searchParameterInfo.isArray()) {
* paramClassName += "[]";}*/

try {
final Class paramClass = ClassUtils.getClass(paramClassName);
Expand All @@ -403,9 +399,43 @@ public CidsServerSearch serverSearchInstanceFromSearchParameters(
} else if (searchParameterInfo.isArray()) {
// jackson created a collection, not an array!
if (Collection.class.isInstance(searchParameter.getValue())) {
paramValue = Arrays.copyOf(((Collection)searchParameter.getValue()).toArray(),
((Collection)searchParameter.getValue()).size(),
paramClass);
final Collection paramCollection = (Collection)searchParameter.getValue();
final Object[] arrayInstance;
if (paramClass.isPrimitive()) {
arrayInstance = (Object[])Array.newInstance(
ClassUtils.primitiveToWrapper(paramClass),
paramCollection.size());
} else {
arrayInstance = (Object[])Array.newInstance(
paramClass,
paramCollection.size());
}

paramClassName += "[]";
/*final Class paramArrayClass = ClassUtils.getClass(paramClassName);
*
* paramValue = Arrays.copyOf( paramCollection.toArray(arrayInstance),
* paramCollection.size(), paramArrayClass);*/

if (paramClass.equals(boolean.class)) {
paramValue = ArrayUtils.toPrimitive((Boolean[])paramCollection.toArray(arrayInstance));
} else if (paramClass.equals(byte.class)) {
paramValue = ArrayUtils.toPrimitive((Byte[])paramCollection.toArray(arrayInstance));
} else if (paramClass.equals(char.class)) {
paramValue = ArrayUtils.toPrimitive((Character[])paramCollection.toArray(arrayInstance));
} else if (paramClass.equals(double.class)) {
paramValue = ArrayUtils.toPrimitive((Double[])paramCollection.toArray(arrayInstance));
} else if (paramClass.equals(float.class)) {
paramValue = ArrayUtils.toPrimitive((Float[])paramCollection.toArray(arrayInstance));
} else if (paramClass.equals(int.class)) {
paramValue = ArrayUtils.toPrimitive((Integer[])paramCollection.toArray(arrayInstance));
} else if (paramClass.equals(long.class)) {
paramValue = ArrayUtils.toPrimitive((Long[])paramCollection.toArray(arrayInstance));
} else if (paramClass.equals(short.class)) {
paramValue = ArrayUtils.toPrimitive((Short[])paramCollection.toArray(arrayInstance));
} else {
paramValue = paramCollection.toArray(arrayInstance);
}
} else {
final String message = "Search Parameter Type Missmatch: Type of parameter '"
+ paramKey + "' specified in search parameter info as '" + paramClassName
Expand Down Expand Up @@ -551,8 +581,9 @@ public SearchParameters searchParametersFromServerSearchInstance(
}

/**
* Converts a ObjectNode search result collection to the respective Java Objects. Support MetaClass, MetaObject,
* MetaNode by default and tries to deserialize binry (Base 64 encoded) and jackson serialized objects.<br>
* Converts a Jackson ObjectNode search result collection to the respective Java Objects. Support MetaClass,
* MetaObject, MetaNode by default and tries to deserialize binary (Base 64 encoded) and jackson serialized objects.
* <br>
* <strong>Warning:</strong><br>
* Does not support automatic deserialization of LightWightMetaObjects! A helper method for LightWightMetaObject
* deserialization is available at
Expand Down

0 comments on commit 7711e9a

Please sign in to comment.