[Major] Json Tags are now in Tags.Json and are drinking camel-case

This commit is contained in:
Robert von Burg 2017-02-02 11:58:59 +01:00
parent c96465fcc6
commit 1d25a2a46b
17 changed files with 418 additions and 1603 deletions

View File

@ -18,8 +18,11 @@ package li.strolch.model;
@SuppressWarnings("nls")
public class Tags {
public static final String RESOURCE = "Resource";
public static final String ORDER = "Order";
public static final String ACTIVITY = "Activity";
public static final String CDATA = "CDATA";
public static final String OBJECT_TYPE = "ObjectType";
public static final String ID = "Id";
public static final String NAME = "Name";
public static final String TYPE = "Type";
@ -33,13 +36,9 @@ public class Tags {
public static final String HIDDEN = "Hidden";
public static final String INDEX = "Index";
public static final String PARAMETER = "Parameter";
public static final String PARAMETERS = "Parameters";
public static final String TIMED_STATE = "TimedState";
public static final String TIMED_STATES = "TimedStates";
public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement";
public static final String RESOURCE = "Resource";
public static final String ORDER = "Order";
public static final String PARAMETER_BAGS = "ParameterBags";
public static final String PARAMETER_BAG = "ParameterBag";
public static final String STROLCH_MODEL = "StrolchModel";
public static final String INCLUDE_FILE = "IncludeFile";
@ -48,13 +47,12 @@ public class Tags {
public static final String AUDIT = "Audit";
public static final String POLICIES = "Policies";
public static final String POLICY = "Policy";
public static final String ELEMENTS = "Elements";
public static final String VERSION = "Version";
public static final String CREATED_AT = "CreatedAt";
public static final String CREATED_BY = "CreatedBy";
public static final String DELETED = "Deleted";
public static final String ACTIVITY = "Activity";
public static final String TIME_ORDERING = "TimeOrdering";
public static final String ACTION = "Action";
public static final String START = "Start";
@ -65,6 +63,58 @@ public class Tags {
public static final String RESOURCE_TYPE = "ResourceType";
public static final String STATE_ID = "StateId";
public static class Json {
// elements
public static final String RESOURCE = "resource";
public static final String ORDER = "order";
public static final String ACTIVITY = "activity";
public static final String OBJECT_TYPE = "objectType";
public static final String ID = "id";
public static final String TYPE = "type";
public static final String NAME = "name";
public static final String DATE = "date";
public static final String STATE = "state";
public static final String TIME_ORDERING = "timeOrdering";
public static final String PARAMETER_BAGS = "parameterBags";
public static final String PARAMETERS = "parameters";
public static final String INTERPRETATION = "interpretation";
public static final String UOM = "uom";
public static final String HIDDEN = "hidden";
public static final String INDEX = "index";
public static final String TIMED_STATES = "timedStates";
public static final String VALUES = "values";
public static final String ACTION = "action";
public static final String RESOURCE_ID = "resourceId";
public static final String RESOURCE_TYPE = "resourceType";
public static final String VALUE_CHANGES = "valueChanges";
public static final String STATE_ID = "stateId";
public static final String VALUE = "value";
public static final String TIME = "time";
public static final String POLICIES = "policies";
public static final String VERSION = "version";
public static final String CREATED_AT = "createdAt";
public static final String CREATED_BY = "createdBy";
public static final String DELETED = "deleted";
// miscellaneous
public static final String ELEMENTS = "elements";
public static final String NR_OF_ELEMENTS = "nrOfElements";
public static final String ELEMENT_MAPS = "elementMaps";
public static final String TYPES = "types";
public static final String REALMS = "realms";
public static final String SIZE = "size";
}
public static class Audit {
public static final String ID = Tags.ID;

View File

@ -46,6 +46,7 @@ import li.strolch.model.timedstate.StrolchTimedState;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.impl.ValueChange;
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.helper.StringHelper;
import li.strolch.utils.iso8601.ISO8601FormatFactory;
/**
@ -64,15 +65,15 @@ public class StrolchElementFromJsonVisitor {
order.setPolicyDefs(defs);
// attributes
if (jsonObject.has(Tags.DATE)) {
String date = jsonObject.get(Tags.DATE).getAsString();
if (jsonObject.has(Tags.Json.DATE)) {
String date = jsonObject.get(Tags.Json.DATE).getAsString();
order.setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(date));
} else {
order.setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse("-")); //$NON-NLS-1$
order.setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(StringHelper.DASH)); //$NON-NLS-1$
}
if (jsonObject.has(Tags.STATE)) {
order.setState(State.parse(jsonObject.get(Tags.STATE).getAsString()));
if (jsonObject.has(Tags.Json.STATE)) {
order.setState(State.parse(jsonObject.get(Tags.Json.STATE).getAsString()));
} else {
order.setState(State.CREATED);
}
@ -89,10 +90,10 @@ public class StrolchElementFromJsonVisitor {
resource.setPolicyDefs(defs);
// time states
if (!jsonObject.has(Tags.TIMED_STATES))
if (!jsonObject.has(Tags.Json.TIMED_STATES))
return;
JsonObject timedStatesJ = jsonObject.getAsJsonObject(Tags.TIMED_STATES);
JsonObject timedStatesJ = jsonObject.getAsJsonObject(Tags.Json.TIMED_STATES);
Set<Entry<String, JsonElement>> entrySet = timedStatesJ.entrySet();
for (Entry<String, JsonElement> entry : entrySet) {
@ -100,7 +101,7 @@ public class StrolchElementFromJsonVisitor {
JsonObject timeStateJ = entry.getValue().getAsJsonObject();
// evaluate type of TimedState
String typeS = timeStateJ.get(Tags.TYPE).getAsString();
String typeS = timeStateJ.get(Tags.Json.TYPE).getAsString();
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + resource.getId(), typeS);
StrolchValueType valueType = StrolchValueType.parse(typeS);
StrolchTimedState<? extends IValue<?>> timedState = valueType.timedStateInstance();
@ -116,29 +117,29 @@ public class StrolchElementFromJsonVisitor {
}
// further attributes
if (timeStateJ.has(Tags.INTERPRETATION))
timedState.setInterpretation(timeStateJ.get(Tags.INTERPRETATION).getAsString());
if (timeStateJ.has(Tags.UOM))
timedState.setUom(timeStateJ.get(Tags.UOM).getAsString());
if (timeStateJ.has(Tags.INDEX))
timedState.setIndex(timeStateJ.get(Tags.INDEX).getAsInt());
if (timeStateJ.has(Tags.HIDDEN))
timedState.setHidden(timeStateJ.get(Tags.HIDDEN).getAsBoolean());
if (timeStateJ.has(Tags.Json.INTERPRETATION))
timedState.setInterpretation(timeStateJ.get(Tags.Json.INTERPRETATION).getAsString());
if (timeStateJ.has(Tags.Json.UOM))
timedState.setUom(timeStateJ.get(Tags.Json.UOM).getAsString());
if (timeStateJ.has(Tags.Json.INDEX))
timedState.setIndex(timeStateJ.get(Tags.Json.INDEX).getAsInt());
if (timeStateJ.has(Tags.Json.HIDDEN))
timedState.setHidden(timeStateJ.get(Tags.Json.HIDDEN).getAsBoolean());
resource.addTimedState(timedState);
if (!timeStateJ.has(Tags.VALUES))
if (!timeStateJ.has(Tags.Json.VALUES))
continue;
JsonArray valuesJ = timeStateJ.getAsJsonArray(Tags.VALUES);
JsonArray valuesJ = timeStateJ.getAsJsonArray(Tags.Json.VALUES);
valuesJ.forEach(e -> {
JsonObject timeValueJ = e.getAsJsonObject();
String timeS = timeValueJ.get(Tags.TIME).getAsString();
String timeS = timeValueJ.get(Tags.Json.TIME).getAsString();
long time = ISO8601FormatFactory.getInstance().parseDate(timeS).getTime();
String valueS = timeValueJ.get(Tags.VALUE).getAsString();
String valueS = timeValueJ.get(Tags.Json.VALUE).getAsString();
timedState.setStateFromStringAt(time, valueS);
});
}
@ -147,9 +148,9 @@ public class StrolchElementFromJsonVisitor {
public void fillElement(JsonObject jsonObject, Activity activity) {
fillElement(jsonObject, (GroupedParameterizedElement) activity);
if (!jsonObject.has(Tags.TIME_ORDERING))
if (!jsonObject.has(Tags.Json.TIME_ORDERING))
throw new StrolchException("TimeOrdering not set on " + activity.getLocator());
String timeOrderingS = jsonObject.get(Tags.TIME_ORDERING).getAsString();
String timeOrderingS = jsonObject.get(Tags.Json.TIME_ORDERING).getAsString();
TimeOrdering timeOrdering = TimeOrdering.parse(timeOrderingS);
activity.setTimeOrdering(timeOrdering);
@ -160,23 +161,23 @@ public class StrolchElementFromJsonVisitor {
if (defs.hasPolicyDefs())
activity.setPolicyDefs(defs);
if (!jsonObject.has(Tags.ELEMENTS))
if (!jsonObject.has(Tags.Json.ELEMENTS))
return;
JsonArray elementsJsonArray = jsonObject.getAsJsonArray(Tags.ELEMENTS);
JsonArray elementsJsonArray = jsonObject.getAsJsonArray(Tags.Json.ELEMENTS);
elementsJsonArray.forEach(e -> {
JsonObject elementJsonObject = e.getAsJsonObject();
String objectType = elementJsonObject.get(Tags.OBJECT_TYPE).getAsString();
String objectType = elementJsonObject.get(Tags.Json.OBJECT_TYPE).getAsString();
switch (objectType) {
case Tags.ACTIVITY:
case Tags.Json.ACTIVITY:
Activity childActivity = new Activity();
fillElement(elementJsonObject, childActivity);
activity.addElement(childActivity);
break;
case Tags.ACTION:
case Tags.Json.ACTION:
Action childAction = new Action();
fillElement(elementJsonObject, childAction);
activity.addElement(childAction);
@ -191,9 +192,9 @@ public class StrolchElementFromJsonVisitor {
}
protected void fillElement(JsonObject jsonObject, AbstractStrolchElement strolchElement) {
if (jsonObject.has(Tags.ID) && jsonObject.has(Tags.NAME)) {
strolchElement.setId(jsonObject.get(Tags.ID).getAsString());
strolchElement.setName(jsonObject.get(Tags.NAME).getAsString());
if (jsonObject.has(Tags.Json.ID) && jsonObject.has(Tags.Json.NAME)) {
strolchElement.setId(jsonObject.get(Tags.Json.ID).getAsString());
strolchElement.setName(jsonObject.get(Tags.Json.NAME).getAsString());
} else {
String msg = "Check the values of the jsonObject: {0} either id or name attribute is null!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, jsonObject);
@ -204,8 +205,8 @@ public class StrolchElementFromJsonVisitor {
protected void fillElement(JsonObject jsonObject, GroupedParameterizedElement groupedParameterizedElement) {
fillElement(jsonObject, (AbstractStrolchElement) groupedParameterizedElement);
if (jsonObject.has(Tags.TYPE)) {
groupedParameterizedElement.setType(jsonObject.get(Tags.TYPE).getAsString());
if (jsonObject.has(Tags.Json.TYPE)) {
groupedParameterizedElement.setType(jsonObject.get(Tags.Json.TYPE).getAsString());
} else {
String msg = "Check the values of the jsonObject: {0} type attribute is null!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, jsonObject);
@ -213,10 +214,10 @@ public class StrolchElementFromJsonVisitor {
}
// add all the parameter bags
if (!jsonObject.has(Tags.PARAMETER_BAGS))
if (!jsonObject.has(Tags.Json.PARAMETER_BAGS))
return;
JsonObject bagsJsonObject = jsonObject.getAsJsonObject(Tags.PARAMETER_BAGS);
JsonObject bagsJsonObject = jsonObject.getAsJsonObject(Tags.Json.PARAMETER_BAGS);
Set<Entry<String, JsonElement>> bags = bagsJsonObject.entrySet();
for (Entry<String, JsonElement> entry : bags) {
@ -244,8 +245,8 @@ public class StrolchElementFromJsonVisitor {
protected void fillElement(JsonObject jsonObject, ParameterizedElement parameterizedElement) {
fillElement(jsonObject, (AbstractStrolchElement) parameterizedElement);
if (jsonObject.has(Tags.TYPE)) {
parameterizedElement.setType(jsonObject.get(Tags.TYPE).getAsString());
if (jsonObject.has(Tags.Json.TYPE)) {
parameterizedElement.setType(jsonObject.get(Tags.Json.TYPE).getAsString());
} else {
String msg = "Check the values of the jsonObject: {0} type attribute is null!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, jsonObject);
@ -253,10 +254,10 @@ public class StrolchElementFromJsonVisitor {
}
// add all the parameters
if (!jsonObject.has(Tags.PARAMETERS))
if (!jsonObject.has(Tags.Json.PARAMETERS))
return;
JsonObject parametersJsonObject = jsonObject.getAsJsonObject(Tags.PARAMETERS);
JsonObject parametersJsonObject = jsonObject.getAsJsonObject(Tags.Json.PARAMETERS);
Set<Entry<String, JsonElement>> parameters = parametersJsonObject.entrySet();
for (Entry<String, JsonElement> entry : parameters) {
String paramId = entry.getKey();
@ -268,7 +269,7 @@ public class StrolchElementFromJsonVisitor {
}
JsonObject paramJsonObject = jsonElement.getAsJsonObject();
String paramtype = paramJsonObject.get(Tags.TYPE).getAsString();
String paramtype = paramJsonObject.get(Tags.Json.TYPE).getAsString();
StrolchValueType paramValueType = StrolchValueType.parse(paramtype);
Parameter<?> parameter = paramValueType.parameterInstance();
@ -286,16 +287,16 @@ public class StrolchElementFromJsonVisitor {
protected void fillElement(JsonObject jsonObject, Parameter<?> param) {
fillElement(jsonObject, (AbstractStrolchElement) param);
if (jsonObject.has(Tags.INTERPRETATION))
param.setInterpretation(jsonObject.get(Tags.INTERPRETATION).getAsString());
if (jsonObject.has(Tags.UOM))
param.setUom(jsonObject.get(Tags.UOM).getAsString());
if (jsonObject.has(Tags.INDEX))
param.setIndex(jsonObject.get(Tags.INDEX).getAsInt());
if (jsonObject.has(Tags.HIDDEN))
param.setHidden(jsonObject.get(Tags.HIDDEN).getAsBoolean());
if (jsonObject.has(Tags.Json.INTERPRETATION))
param.setInterpretation(jsonObject.get(Tags.Json.INTERPRETATION).getAsString());
if (jsonObject.has(Tags.Json.UOM))
param.setUom(jsonObject.get(Tags.Json.UOM).getAsString());
if (jsonObject.has(Tags.Json.INDEX))
param.setIndex(jsonObject.get(Tags.Json.INDEX).getAsInt());
if (jsonObject.has(Tags.Json.HIDDEN))
param.setHidden(jsonObject.get(Tags.Json.HIDDEN).getAsBoolean());
String value = jsonObject.get(Tags.VALUE).getAsString();
String value = jsonObject.get(Tags.Json.VALUE).getAsString();
param.setValueFromString(value);
}
@ -303,12 +304,12 @@ public class StrolchElementFromJsonVisitor {
fillElement(jsonObject, (GroupedParameterizedElement) action);
// attributes
if (jsonObject.has(Tags.RESOURCE_ID))
action.setResourceId(jsonObject.get(Tags.RESOURCE_ID).getAsString());
if (jsonObject.has(Tags.RESOURCE_TYPE))
action.setResourceType(jsonObject.get(Tags.RESOURCE_TYPE).getAsString());
if (jsonObject.has(Tags.STATE))
action.setState(State.parse(jsonObject.get(Tags.STATE).getAsString()));
if (jsonObject.has(Tags.Json.RESOURCE_ID))
action.setResourceId(jsonObject.get(Tags.Json.RESOURCE_ID).getAsString());
if (jsonObject.has(Tags.Json.RESOURCE_TYPE))
action.setResourceType(jsonObject.get(Tags.Json.RESOURCE_TYPE).getAsString());
if (jsonObject.has(Tags.Json.STATE))
action.setState(State.parse(jsonObject.get(Tags.Json.STATE).getAsString()));
// policies
PolicyDefs defs = parsePolicies(jsonObject);
@ -316,18 +317,18 @@ public class StrolchElementFromJsonVisitor {
action.setPolicyDefs(defs);
// value changes
if (!jsonObject.has(Tags.VALUE_CHANGES))
if (!jsonObject.has(Tags.Json.VALUE_CHANGES))
return;
JsonArray valueChangesJ = jsonObject.getAsJsonArray(Tags.VALUE_CHANGES);
JsonArray valueChangesJ = jsonObject.getAsJsonArray(Tags.Json.VALUE_CHANGES);
valueChangesJ.forEach(e -> {
try {
JsonObject valueChangeJ = e.getAsJsonObject();
String stateId = valueChangeJ.get(Tags.STATE_ID).getAsString();
String timeS = valueChangeJ.get(Tags.TIME).getAsString();
String valueS = valueChangeJ.get(Tags.VALUE).getAsString();
String typeS = valueChangeJ.get(Tags.TYPE).getAsString();
String stateId = valueChangeJ.get(Tags.Json.STATE_ID).getAsString();
String timeS = valueChangeJ.get(Tags.Json.TIME).getAsString();
String valueS = valueChangeJ.get(Tags.Json.VALUE).getAsString();
String typeS = valueChangeJ.get(Tags.Json.TYPE).getAsString();
StrolchValueType type = StrolchValueType.parse(typeS);
IValue<?> value = type.valueInstance(valueS);
@ -349,10 +350,10 @@ public class StrolchElementFromJsonVisitor {
PolicyDefs policyDefs = new PolicyDefs();
if (!jsonObject.has(Tags.POLICIES))
if (!jsonObject.has(Tags.Json.POLICIES))
return policyDefs;
JsonObject policiesJsonObject = jsonObject.getAsJsonObject(Tags.POLICIES);
JsonObject policiesJsonObject = jsonObject.getAsJsonObject(Tags.Json.POLICIES);
Set<Entry<String, JsonElement>> entrySet = policiesJsonObject.entrySet();
for (Entry<String, JsonElement> entry : entrySet) {
@ -368,16 +369,16 @@ public class StrolchElementFromJsonVisitor {
protected void parseVersion(StrolchRootElement rootElement, JsonObject jsonObject) {
if (!jsonObject.has(Tags.VERSION))
if (!jsonObject.has(Tags.Json.VERSION))
return;
JsonObject versionJ = jsonObject.getAsJsonObject(Tags.VERSION);
JsonObject versionJ = jsonObject.getAsJsonObject(Tags.Json.VERSION);
int v = versionJ.get(Tags.VERSION).getAsInt();
String createdBy = versionJ.get(Tags.CREATED_BY).getAsString();
String createdAtS = versionJ.get(Tags.CREATED_AT).getAsString();
int v = versionJ.get(Tags.Json.VERSION).getAsInt();
String createdBy = versionJ.get(Tags.Json.CREATED_BY).getAsString();
String createdAtS = versionJ.get(Tags.Json.CREATED_AT).getAsString();
Date createdAt = ISO8601FormatFactory.getInstance().parseDate(createdAtS);
boolean deleted = versionJ.get(Tags.DELETED).getAsBoolean();
boolean deleted = versionJ.get(Tags.Json.DELETED).getAsBoolean();
Version version = new Version(rootElement.getLocator(), v, createdBy, createdAt, deleted);
rootElement.setVersion(version);

View File

@ -34,7 +34,7 @@ public class StrolchElementToJsonVisitor {
public JsonObject toJson(Resource element) {
JsonObject rootJ = new JsonObject();
rootJ.addProperty(Tags.OBJECT_TYPE, Tags.RESOURCE);
rootJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.RESOURCE);
toJson(element, rootJ);
@ -49,11 +49,11 @@ public class StrolchElementToJsonVisitor {
public JsonObject toJson(Order element) {
JsonObject rootJ = new JsonObject();
rootJ.addProperty(Tags.OBJECT_TYPE, Tags.ORDER);
rootJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ORDER);
toJson(element, rootJ);
rootJ.addProperty(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(element.getDate()));
rootJ.addProperty(Tags.STATE, element.getState().getName());
rootJ.addProperty(Tags.Json.DATE, ISO8601FormatFactory.getInstance().formatDate(element.getDate()));
rootJ.addProperty(Tags.Json.STATE, element.getState().getName());
addVersion(element, rootJ);
addParameterBags(element, rootJ);
@ -75,9 +75,9 @@ public class StrolchElementToJsonVisitor {
protected JsonObject toJson(Activity element, JsonObject rootJ) {
rootJ.addProperty(Tags.OBJECT_TYPE, Tags.ACTIVITY);
rootJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ACTIVITY);
rootJ.addProperty(Tags.TIME_ORDERING, element.getTimeOrdering().getName());
rootJ.addProperty(Tags.Json.TIME_ORDERING, element.getTimeOrdering().getName());
toJson((AbstractStrolchElement) element, rootJ);
@ -88,7 +88,7 @@ public class StrolchElementToJsonVisitor {
if (iter.hasNext()) {
JsonArray elementsJ = new JsonArray();
rootJ.add(Tags.ELEMENTS, elementsJ);
rootJ.add(Tags.Json.ELEMENTS, elementsJ);
while (iter.hasNext()) {
IActivityElement activityElement = iter.next().getValue();
@ -111,15 +111,15 @@ public class StrolchElementToJsonVisitor {
protected JsonObject toJson(Action element, JsonObject rootJ) {
rootJ.addProperty(Tags.OBJECT_TYPE, Tags.ACTION);
rootJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ACTION);
rootJ.addProperty(Tags.STATE, element.getState().getName());
rootJ.addProperty(Tags.Json.STATE, element.getState().getName());
// attributes
toJson((AbstractStrolchElement) element, rootJ);
rootJ.addProperty(Tags.RESOURCE_ID, element.getResourceId());
rootJ.addProperty(Tags.RESOURCE_TYPE, element.getResourceType());
rootJ.addProperty(Tags.STATE, element.getState().name());
rootJ.addProperty(Tags.Json.RESOURCE_ID, element.getResourceId());
rootJ.addProperty(Tags.Json.RESOURCE_TYPE, element.getResourceType());
rootJ.addProperty(Tags.Json.STATE, element.getState().name());
addParameterBags(element, rootJ);
addPolicies(element, rootJ);
@ -129,17 +129,17 @@ public class StrolchElementToJsonVisitor {
if (iter.hasNext()) {
JsonArray changesJ = new JsonArray();
rootJ.add(Tags.VALUE_CHANGES, changesJ);
rootJ.add(Tags.Json.VALUE_CHANGES, changesJ);
while (iter.hasNext()) {
IValueChange<? extends IValue<?>> valueChange = iter.next();
JsonObject changeJ = new JsonObject();
changeJ.addProperty(Tags.STATE_ID, valueChange.getStateId());
changeJ.addProperty(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(valueChange.getTime()));
changeJ.addProperty(Tags.VALUE, valueChange.getValue().getValueAsString());
changeJ.addProperty(Tags.TYPE, valueChange.getValue().getType());
changeJ.addProperty(Tags.Json.STATE_ID, valueChange.getStateId());
changeJ.addProperty(Tags.Json.TIME, ISO8601FormatFactory.getInstance().formatDate(valueChange.getTime()));
changeJ.addProperty(Tags.Json.VALUE, valueChange.getValue().getValueAsString());
changeJ.addProperty(Tags.Json.TYPE, valueChange.getValue().getType());
changesJ.add(changeJ);
}
@ -155,7 +155,7 @@ public class StrolchElementToJsonVisitor {
PolicyDefs policyDefs = policyContainer.getPolicyDefs();
JsonObject policyDefsJ = new JsonObject();
rootJ.add(Tags.POLICIES, policyDefsJ);
rootJ.add(Tags.Json.POLICIES, policyDefsJ);
for (String type : policyDefs.getPolicyTypes()) {
PolicyDef policyDef = policyDefs.getPolicyDef(type);
@ -165,9 +165,9 @@ public class StrolchElementToJsonVisitor {
protected JsonObject toJson(AbstractStrolchElement element, JsonObject rootJ) {
rootJ.addProperty(Tags.ID, element.getId());
rootJ.addProperty(Tags.NAME, element.getName());
rootJ.addProperty(Tags.TYPE, element.getType());
rootJ.addProperty(Tags.Json.ID, element.getId());
rootJ.addProperty(Tags.Json.NAME, element.getName());
rootJ.addProperty(Tags.Json.TYPE, element.getType());
return rootJ;
}
@ -178,7 +178,7 @@ public class StrolchElementToJsonVisitor {
return;
JsonObject parameterBagsJ = new JsonObject();
rootJ.add(Tags.PARAMETER_BAGS, parameterBagsJ);
rootJ.add(Tags.Json.PARAMETER_BAGS, parameterBagsJ);
for (String bagKey : element.getParameterBagKeySet()) {
ParameterBag bag = element.getParameterBag(bagKey);
@ -192,7 +192,7 @@ public class StrolchElementToJsonVisitor {
continue;
JsonObject paramsJ = new JsonObject();
bagJ.add(Tags.PARAMETERS, paramsJ);
bagJ.add(Tags.Json.PARAMETERS, paramsJ);
for (String paramKey : bag.getParameterKeySet()) {
Parameter<?> param = bag.getParameter(paramKey);
@ -203,18 +203,18 @@ public class StrolchElementToJsonVisitor {
toJson((AbstractStrolchElement) param, paramJ);
if (!StrolchModelConstants.INTERPRETATION_NONE.equals(param.getInterpretation()))
paramJ.addProperty(Tags.INTERPRETATION, param.getInterpretation());
paramJ.addProperty(Tags.Json.INTERPRETATION, param.getInterpretation());
if (param.isHidden())
paramJ.addProperty(Tags.HIDDEN, param.isHidden());
paramJ.addProperty(Tags.Json.HIDDEN, param.isHidden());
if (!StrolchModelConstants.UOM_NONE.equals(param.getUom()))
paramJ.addProperty(Tags.UOM, param.getUom());
paramJ.addProperty(Tags.Json.UOM, param.getUom());
if (param.getIndex() != 0)
paramJ.addProperty(Tags.INDEX, param.getIndex());
paramJ.addProperty(Tags.Json.INDEX, param.getIndex());
paramJ.addProperty(Tags.VALUE, param.getValueAsString());
paramJ.addProperty(Tags.Json.VALUE, param.getValueAsString());
}
}
}
@ -225,7 +225,7 @@ public class StrolchElementToJsonVisitor {
return;
JsonObject timedStatesJ = new JsonObject();
rootJ.add(Tags.TIMED_STATES, timedStatesJ);
rootJ.add(Tags.Json.TIMED_STATES, timedStatesJ);
for (String stateKey : element.getTimedStateKeySet()) {
StrolchTimedState<IValue<?>> state = element.getTimedState(stateKey);
@ -236,7 +236,7 @@ public class StrolchElementToJsonVisitor {
toJson((AbstractStrolchElement) state, stateJ);
JsonArray valuesJ = new JsonArray();
stateJ.add(Tags.VALUES, valuesJ);
stateJ.add(Tags.Json.VALUES, valuesJ);
SortedSet<ITimeValue<IValue<?>>> values = state.getTimeEvolution().getValues();
for (ITimeValue<IValue<?>> value : values) {
@ -247,8 +247,8 @@ public class StrolchElementToJsonVisitor {
Long time = value.getTime();
String valueS = value.getValue().getValueAsString();
valueJ.addProperty(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
valueJ.addProperty(Tags.VALUE, valueS);
valueJ.addProperty(Tags.Json.TIME, ISO8601FormatFactory.getInstance().formatDate(time));
valueJ.addProperty(Tags.Json.VALUE, valueS);
}
}
}
@ -260,10 +260,10 @@ public class StrolchElementToJsonVisitor {
Version version = element.getVersion();
JsonObject versionJ = new JsonObject();
versionJ.addProperty(Tags.VERSION, version.getVersion());
versionJ.addProperty(Tags.CREATED_BY, version.getCreatedBy());
versionJ.addProperty(Tags.CREATED_AT, ISO8601FormatFactory.getInstance().formatDate(version.getCreatedAt()));
versionJ.addProperty(Tags.DELETED, version.isDeleted());
rootJ.add(Tags.VERSION, versionJ);
versionJ.addProperty(Tags.Json.VERSION, version.getVersion());
versionJ.addProperty(Tags.Json.CREATED_BY, version.getCreatedBy());
versionJ.addProperty(Tags.Json.CREATED_AT, ISO8601FormatFactory.getInstance().formatDate(version.getCreatedAt()));
versionJ.addProperty(Tags.Json.DELETED, version.isDeleted());
rootJ.add(Tags.Json.VERSION, versionJ);
}
}

View File

@ -30,7 +30,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.parsers.SAXParser;
@ -38,12 +37,19 @@ import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import li.strolch.agent.api.ActivityMap;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.OrderMap;
import li.strolch.agent.api.ResourceMap;
import li.strolch.exception.StrolchException;
import li.strolch.model.Order;
import li.strolch.model.Resource;
import li.strolch.model.Tags;
import li.strolch.model.activity.Activity;
import li.strolch.model.json.OrderToJsonVisitor;
import li.strolch.model.json.ResourceToJsonVisitor;
import li.strolch.model.xml.OrderToXmlStringVisitor;
@ -55,23 +61,13 @@ import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.privilege.model.Certificate;
import li.strolch.rest.RestfulStrolchComponent;
import li.strolch.rest.StrolchRestfulConstants;
import li.strolch.rest.model.AgentOverview;
import li.strolch.rest.model.ElementMapOverview;
import li.strolch.rest.model.ElementMapType;
import li.strolch.rest.model.ElementMapsOverview;
import li.strolch.rest.model.OrderOverview;
import li.strolch.rest.model.RealmDetail;
import li.strolch.rest.model.RealmOverview;
import li.strolch.rest.model.ResourceOverview;
import li.strolch.rest.model.Result;
import li.strolch.rest.model.StrolchElementOverview;
import li.strolch.rest.model.TypeDetail;
import li.strolch.rest.model.TypeOverview;
import li.strolch.service.UpdateOrderService;
import li.strolch.service.UpdateOrderService.UpdateOrderArg;
import li.strolch.service.UpdateResourceService;
import li.strolch.service.UpdateResourceService.UpdateResourceArg;
import li.strolch.service.api.ServiceResult;
import li.strolch.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
@ -94,36 +90,39 @@ public class Inspector {
* </p>
*
* @return the root element, which is an overview of the configured realms
*
* @see AgentOverview
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAgent(@Context HttpServletRequest request) {
try {
ComponentContainer container = RestfulStrolchComponent.getInstance().getContainer();
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
JsonObject agentOverview = new JsonObject();
JsonArray realmsArr = new JsonArray();
agentOverview.add(Tags.Json.REALMS, realmsArr);
ComponentContainer container = RestfulStrolchComponent.getInstance().getContainer();
Set<String> realmNames = container.getRealmNames();
List<RealmOverview> realmOverviews = new ArrayList<>(realmNames.size());
for (String realmName : realmNames) {
JsonObject realmJ = new JsonObject();
try (StrolchTransaction tx = openTx(cert, realmName)) {
long size = 0;
size += tx.getResourceMap().querySize(tx);
size += tx.getOrderMap().querySize(tx);
RealmOverview realmOverview = new RealmOverview(realmName, size);
realmOverviews.add(realmOverview);
realmJ.addProperty(Tags.Json.NAME, realmName);
realmJ.addProperty(Tags.Json.SIZE, size);
realmsArr.add(realmJ);
}
}
AgentOverview agentOverview = new AgentOverview(realmOverviews);
GenericEntity<AgentOverview> entity = new GenericEntity<AgentOverview>(agentOverview, AgentOverview.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(agentOverview.toString()).build();
} catch (Exception e) {
//e.printStackTrace();
throw e;
}
}
@ -141,36 +140,58 @@ public class Inspector {
* the realm for which the overview is to be returned
*
* @return the overview of a specific relam
*
* @see RealmDetail
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}")
public Response getRealm(@PathParam("realm") String realm, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
List<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2);
JsonObject realmDetailJ = new JsonObject();
JsonArray elementMapsArr = new JsonArray();
realmDetailJ.add(Tags.Json.ELEMENT_MAPS, elementMapsArr);
try (StrolchTransaction tx = openTx(cert, realm)) {
ResourceMap resourceMap = tx.getResourceMap();
ElementMapsOverview resourceOverview = new ElementMapsOverview(ElementMapType.RESOURCE);
resourceOverview.setNrOfElements(resourceMap.querySize(tx));
resourceOverview.setTypes(resourceMap.getTypes(tx));
elementMapOverviews.add(resourceOverview);
{
ResourceMap resourceMap = tx.getResourceMap();
JsonObject elementMapJ = new JsonObject();
elementMapJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.RESOURCE);
elementMapJ.addProperty(Tags.Json.NR_OF_ELEMENTS, resourceMap.querySize(tx));
JsonArray typesJ = new JsonArray();
resourceMap.getTypes(tx).forEach(type -> typesJ.add(new JsonPrimitive(type)));
elementMapJ.add(Tags.Json.TYPES, typesJ);
OrderMap orderMap = tx.getOrderMap();
ElementMapsOverview orderOverview = new ElementMapsOverview(ElementMapType.ORDER);
orderOverview.setNrOfElements(orderMap.querySize(tx));
orderOverview.setTypes(orderMap.getTypes(tx));
elementMapOverviews.add(orderOverview);
elementMapsArr.add(elementMapJ);
}
{
OrderMap orderMap = tx.getOrderMap();
JsonObject elementMapJ = new JsonObject();
elementMapJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ORDER);
elementMapJ.addProperty(Tags.Json.NR_OF_ELEMENTS, orderMap.querySize(tx));
JsonArray typesJ = new JsonArray();
orderMap.getTypes(tx).forEach(type -> typesJ.add(new JsonPrimitive(type)));
elementMapJ.add(Tags.Json.TYPES, typesJ);
elementMapsArr.add(elementMapJ);
}
{
ActivityMap activityMap = tx.getActivityMap();
JsonObject elementMapJ = new JsonObject();
elementMapJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ACTIVITY);
elementMapJ.addProperty(Tags.Json.NR_OF_ELEMENTS, activityMap.querySize(tx));
JsonArray typesJ = new JsonArray();
activityMap.getTypes(tx).forEach(type -> typesJ.add(new JsonPrimitive(type)));
elementMapJ.add(Tags.Json.TYPES, typesJ);
elementMapsArr.add(elementMapJ);
}
}
RealmDetail modelOverview = new RealmDetail(elementMapOverviews);
GenericEntity<RealmDetail> entity = new GenericEntity<RealmDetail>(modelOverview, RealmDetail.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(realmDetailJ.toString()).build();
}
/**
@ -185,35 +206,38 @@ public class Inspector {
* the realm for which the resource overview is to be returned
*
* @return an overview of the {@link Resource Resources}. This is a list of all the types and the size each type has
*
* @see ElementMapOverview
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/Resource")
@Path("{realm}/resources")
public Response getResourcesOverview(@PathParam("realm") String realm, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
ElementMapOverview resourcesOverview;
JsonObject mapOverview = new JsonObject();
try (StrolchTransaction tx = openTx(cert, realm)) {
ResourceMap resourceMap = tx.getResourceMap();
List<String> types = new ArrayList<>(resourceMap.getTypes(tx));
Collections.sort(types);
List<TypeOverview> typeOverviews = new ArrayList<>(types.size());
for (String type : types) {
long size = resourceMap.querySize(tx, type);
TypeOverview typeOverview = new TypeOverview(type, size);
typeOverviews.add(typeOverview);
}
resourcesOverview = new ElementMapOverview(ElementMapType.RESOURCE.getName(), typeOverviews);
mapOverview.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.RESOURCE);
mapOverview.addProperty(Tags.Json.SIZE, resourceMap.querySize(tx));
JsonArray typeArrJ = new JsonArray();
mapOverview.add(Tags.Json.TYPES, typeArrJ);
List<String> types = new ArrayList<>();
Collections.sort(types);
resourceMap.getTypes(tx).forEach(type -> {
JsonObject typeJ = new JsonObject();
typeJ.addProperty(Tags.Json.TYPE, type);
typeJ.addProperty(Tags.Json.SIZE, resourceMap.querySize(tx, type));
typeArrJ.add(typeJ);
});
}
GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(resourcesOverview,
ElementMapOverview.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(mapOverview.toString()).build();
}
/**
@ -228,35 +252,86 @@ public class Inspector {
* the realm for which the order overview is to be returned
*
* @return an overview of the {@link Order Orders}. This is a list of all the types and the size each type has
*
* @see ElementMapOverview
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/Order")
@Path("{realm}/orders")
public Response getOrdersOverview(@PathParam("realm") String realm, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
ElementMapOverview ordersOverview;
JsonObject mapOverview = new JsonObject();
try (StrolchTransaction tx = openTx(cert, realm)) {
OrderMap orderMap = tx.getOrderMap();
List<String> types = new ArrayList<>(orderMap.getTypes(tx));
Collections.sort(types);
List<TypeOverview> typeOverviews = new ArrayList<>(types.size());
for (String type : types) {
long size = orderMap.querySize(tx, type);
TypeOverview typeOverview = new TypeOverview(type, size);
typeOverviews.add(typeOverview);
}
ordersOverview = new ElementMapOverview(ElementMapType.ORDER.getName(), typeOverviews);
mapOverview.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ORDER);
mapOverview.addProperty(Tags.Json.SIZE, orderMap.querySize(tx));
JsonArray typeArrJ = new JsonArray();
mapOverview.add(Tags.Json.TYPES, typeArrJ);
List<String> types = new ArrayList<>();
Collections.sort(types);
orderMap.getTypes(tx).forEach(type -> {
JsonObject typeJ = new JsonObject();
typeJ.addProperty(Tags.Json.TYPE, type);
typeJ.addProperty(Tags.Json.SIZE, orderMap.querySize(tx, type));
typeArrJ.add(typeJ);
});
}
GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(ordersOverview,
ElementMapOverview.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(mapOverview.toString()).build();
}
/**
* <p>
* Activity inspector
* </p>
* <p>
* Returns an overview of the {@link Activity Activities}. This is a list of all the types and the size each type
* has
* </p>
*
* @param realm
* the realm for which the activity overview is to be returned
*
* @return an overview of the {@link Activity Activities}. This is a list of all the types and the size each type
* has
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/activities")
public Response getActivitiesOverview(@PathParam("realm") String realm, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
JsonObject mapOverview = new JsonObject();
try (StrolchTransaction tx = openTx(cert, realm)) {
ActivityMap activityMap = tx.getActivityMap();
mapOverview.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ACTIVITY);
mapOverview.addProperty(Tags.Json.SIZE, activityMap.querySize(tx));
JsonArray typeArrJ = new JsonArray();
mapOverview.add(Tags.Json.TYPES, typeArrJ);
List<String> types = new ArrayList<>();
Collections.sort(types);
activityMap.getTypes(tx).forEach(type -> {
JsonObject typeJ = new JsonObject();
typeJ.addProperty(Tags.Json.TYPE, type);
typeJ.addProperty(Tags.Json.SIZE, activityMap.querySize(tx, type));
typeArrJ.add(typeJ);
});
}
return Response.ok().entity(mapOverview.toString()).build();
}
// TODO for the get element type details, we should not simply query all objects, but rather find a solution to query only the id, name, type and date, state for the order
@ -282,26 +357,33 @@ public class Inspector {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/Resource/{type}")
@Path("{realm}/resources/{type}")
public Response getResourceTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type,
@Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
TypeDetail typeDetail;
JsonObject typeDetailJ = new JsonObject();
typeDetailJ.addProperty(Tags.Json.TYPE, type);
JsonArray elementsJ = new JsonArray();
typeDetailJ.add(Tags.Json.ELEMENTS, elementsJ);
try (StrolchTransaction tx = openTx(cert, realm)) {
List<Resource> byType = tx.getResourceMap().getElementsBy(tx, type);
List<StrolchElementOverview> elementOverviews = new ArrayList<>(byType.size());
for (Resource resource : byType) {
ResourceOverview resourceOverview = new ResourceOverview(resource);
elementOverviews.add(resourceOverview);
JsonObject elementJ = new JsonObject();
elementJ.addProperty(Tags.Json.ID, resource.getId());
elementJ.addProperty(Tags.Json.NAME, resource.getName());
elementJ.addProperty(Tags.Json.TYPE, resource.getType());
elementsJ.add(elementJ);
}
typeDetail = new TypeDetail(type, elementOverviews);
}
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(typeDetailJ.toString()).build();
}
/**
@ -323,26 +405,85 @@ public class Inspector {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/Order/{type}")
@Path("{realm}/orders/{type}")
public Response getOrderTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type,
@Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
TypeDetail typeDetail;
JsonObject typeDetailJ = new JsonObject();
typeDetailJ.addProperty(Tags.Json.TYPE, type);
JsonArray elementsJ = new JsonArray();
typeDetailJ.add(Tags.Json.ELEMENTS, elementsJ);
try (StrolchTransaction tx = openTx(cert, realm)) {
List<Order> byType = tx.getOrderMap().getElementsBy(tx, type);
List<StrolchElementOverview> elementOverviews = new ArrayList<>(byType.size());
for (Order order : byType) {
OrderOverview orderOverview = new OrderOverview(order);
elementOverviews.add(orderOverview);
JsonObject elementJ = new JsonObject();
elementJ.addProperty(Tags.Json.ID, order.getId());
elementJ.addProperty(Tags.Json.NAME, order.getName());
elementJ.addProperty(Tags.Json.TYPE, order.getType());
elementJ.addProperty(Tags.Json.STATE, order.getState().getName());
elementJ.addProperty(Tags.Json.DATE, ISO8601FormatFactory.getInstance().formatDate(order.getDate()));
elementsJ.add(elementJ);
}
typeDetail = new TypeDetail(type, elementOverviews);
}
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
//
};
return Response.ok().entity(entity).build();
return Response.ok().entity(typeDetailJ.toString()).build();
}
/**
* <p>
* Order type inspector
* </p>
* <p>
* Returns an overview of the {@link Order Orders} with the given type. This is a list of overviews of the orders
* </p>
*
* @param realm
* the realm for which the order type overview is to be returned
* @param type
*
* @return an overview of the {@link Order Orders} with the given type. This is a list of overviews of the orders
*
* @see TypeDetail
* @see StrolchElementOverview
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/activities/{type}")
public Response getActivities(@PathParam("realm") String realm, @PathParam("type") String type,
@Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
JsonObject typeDetailJ = new JsonObject();
typeDetailJ.addProperty(Tags.Json.TYPE, type);
JsonArray elementsJ = new JsonArray();
typeDetailJ.add(Tags.Json.ELEMENTS, elementsJ);
try (StrolchTransaction tx = openTx(cert, realm)) {
List<Activity> byType = tx.getActivityMap().getElementsBy(tx, type);
for (Activity activity : byType) {
JsonObject elementJ = new JsonObject();
elementJ.addProperty(Tags.Json.ID, activity.getId());
elementJ.addProperty(Tags.Json.NAME, activity.getName());
elementJ.addProperty(Tags.Json.TYPE, activity.getType());
elementJ.addProperty(Tags.Json.STATE, activity.getState().getName());
elementJ.addProperty(Tags.Json.TIME_ORDERING, activity.getTimeOrdering().getName());
elementsJ.add(elementJ);
}
}
return Response.ok().entity(typeDetailJ.toString()).build();
}
/**
@ -367,9 +508,10 @@ public class Inspector {
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/Resource/{type}/{id}")
@Path("{realm}/resources/{type}/{id}")
public Response getResourceAsJson(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
Resource resource;
@ -388,6 +530,7 @@ public class Inspector {
@Path("{realm}/Resource/{type}/{id}")
public Response getResourceAsXml(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
Resource resource;
@ -405,9 +548,10 @@ public class Inspector {
@PUT
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
@Path("{realm}/Resource/{type}/{id}")
@Path("{realm}/resources/{type}/{id}")
public Response updateResourceAsXml(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id, String data, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
Resource resource;
@ -446,9 +590,10 @@ public class Inspector {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/Order/{type}/{id}")
@Path("{realm}/orders/{type}/{id}")
public Response getOrderAsJson(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
Order order;
@ -464,9 +609,10 @@ public class Inspector {
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("{realm}/Order/{type}/{id}")
@Path("{realm}/orders/{type}/{id}")
public Response getOrderAsXml(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
Order order;
@ -484,9 +630,10 @@ public class Inspector {
@PUT
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
@Path("{realm}/Order/{type}/{id}")
@Path("{realm}/orders/{type}/{id}")
public Response updateOrderAsXml(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id, String data, @Context HttpServletRequest request) {
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
Order order;

View File

@ -1,88 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import java.text.MessageFormat;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Agent")
public class AgentOverview {
@XmlElement(name = "realms")
private List<RealmOverview> realms;
public AgentOverview() {
// no-arg constructor for JAXB
}
public AgentOverview(List<RealmOverview> realms) {
this.realms = realms;
}
/**
* @return the realms
*/
public List<RealmOverview> getRealms() {
return this.realms;
}
/**
* @param realms
* the realms to set
*/
public void setRealms(List<RealmOverview> realms) {
this.realms = realms;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.realms == null) ? 0 : this.realms.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AgentOverview other = (AgentOverview) obj;
if (this.realms == null) {
if (other.realms != null)
return false;
} else if (!this.realms.equals(other.realms))
return false;
return true;
}
@Override
public String toString() {
return MessageFormat.format("AgentOverview [realms={0}]", this.realms); //$NON-NLS-1$
}
}

View File

@ -1,140 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import java.text.MessageFormat;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "ElementMap")
public class ElementMapOverview {
@XmlAttribute(name = "elementMapName")
private String elementMapName;
@XmlAttribute(name = "size")
private long size;
@XmlElement(name = "types", type = TypeOverview.class)
private List<TypeOverview> typeOverviews;
public ElementMapOverview() {
// no-arg constructor for JAXB
}
/**
* @param elementMapName
* @param typeOverviews
*/
public ElementMapOverview(String elementMapName, List<TypeOverview> typeOverviews) {
this.elementMapName = elementMapName;
this.typeOverviews = typeOverviews;
this.size = this.typeOverviews.size();
}
/**
* @return the elementMapName
*/
public String getElementMapName() {
return this.elementMapName;
}
/**
* @param elementMapName
* the elementMapName to set
*/
public void setElementMapName(String elementMapName) {
this.elementMapName = elementMapName;
}
/**
* @return the size
*/
public long getSize() {
return this.size;
}
/**
* @param size
* the size to set
*/
public void setSize(long size) {
this.size = size;
}
/**
* @return the typeOverviews
*/
public List<TypeOverview> getTypeOverviews() {
return this.typeOverviews;
}
/**
* @param typeOverviews
* the typeOverviews to set
*/
public void setTypeOverviews(List<TypeOverview> typeOverviews) {
this.typeOverviews = typeOverviews;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementMapName == null) ? 0 : this.elementMapName.hashCode());
result = prime * result + (int) (this.size ^ (this.size >>> 32));
result = prime * result + ((this.typeOverviews == null) ? 0 : this.typeOverviews.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ElementMapOverview other = (ElementMapOverview) obj;
if (this.elementMapName == null) {
if (other.elementMapName != null)
return false;
} else if (!this.elementMapName.equals(other.elementMapName))
return false;
if (this.size != other.size)
return false;
if (this.typeOverviews == null) {
if (other.typeOverviews != null)
return false;
} else if (!this.typeOverviews.equals(other.typeOverviews))
return false;
return true;
}
@Override
public String toString() {
return MessageFormat.format(
"ElementMapOverview [elementMapName={0}, size={1}, typeOverviews={2}]", this.elementMapName, //$NON-NLS-1$
this.size, this.typeOverviews);
}
}

View File

@ -1,37 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import li.strolch.model.Tags;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public enum ElementMapType {
RESOURCE(Tags.RESOURCE), ORDER(Tags.ORDER);
private String name;
private ElementMapType(String name) {
this.name = name;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
}

View File

@ -1,181 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "ElementMaps")
public class ElementMapsOverview {
@XmlAttribute(name = "name")
private String name;
@XmlAttribute(name = "elementMapType")
private ElementMapType elementMapType;
@XmlAttribute(name = "nrOfElements")
private long nrOfElements;
@XmlElement(name = "types")
private Set<String> types;
public ElementMapsOverview() {
// no-arg constructor for JAXB
}
/**
* @param elementMapType
*/
public ElementMapsOverview(ElementMapType elementMapType) {
this.elementMapType = elementMapType;
this.name = elementMapType.getName();
}
/**
*
* @param elementMapType
* @param nrOfElements
* @param types
*/
public ElementMapsOverview(ElementMapType elementMapType, long nrOfElements, Set<String> types) {
this(elementMapType);
this.nrOfElements = nrOfElements;
this.types = types;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the elementMapType
*/
public ElementMapType getElementMapType() {
return this.elementMapType;
}
/**
* @param elementMapType
* the elementMapType to set
*/
public void setElementMapType(ElementMapType elementMapType) {
this.elementMapType = elementMapType;
}
/**
* @return the types
*/
public Set<String> getTypes() {
return this.types;
}
/**
* @param types
* the types to set
*/
public void setTypes(Set<String> types) {
this.types = types;
}
/**
* @return the nrOfElements
*/
public long getNrOfElements() {
return this.nrOfElements;
}
/**
* @param nrOfElements
* the nrOfElements to set
*/
public void setNrOfElements(long nrOfElements) {
this.nrOfElements = nrOfElements;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementMapType == null) ? 0 : this.elementMapType.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + (int) (this.nrOfElements ^ (this.nrOfElements >>> 32));
result = prime * result + ((this.types == null) ? 0 : this.types.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ElementMapsOverview other = (ElementMapsOverview) obj;
if (this.elementMapType != other.elementMapType)
return false;
if (this.name == null) {
if (other.name != null)
return false;
} else if (!this.name.equals(other.name))
return false;
if (this.nrOfElements != other.nrOfElements)
return false;
if (this.types == null) {
if (other.types != null)
return false;
} else if (!this.types.equals(other.types))
return false;
return true;
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ElementMapsOverview [name=");
sb.append(this.name);
sb.append(", elementMapType=");
sb.append(this.elementMapType);
sb.append(", nrOfElements=");
sb.append(this.nrOfElements);
sb.append(", types=");
sb.append(this.types);
sb.append("]");
return sb.toString();
}
}

View File

@ -1,122 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.Order;
import li.strolch.model.State;
import li.strolch.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Order")
public class OrderOverview extends StrolchElementOverview {
@XmlAttribute(name = "date")
private String date;
@XmlAttribute(name = "state")
private State state;
public OrderOverview() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
*/
public OrderOverview(String id, String name, String type, Date date, State state) {
super(id, name, type);
this.state = state;
this.date = ISO8601FormatFactory.getInstance().formatDate(date);
}
/**
* @param order
*/
public OrderOverview(Order order) {
super(order);
this.state = order.getState();
this.date = ISO8601FormatFactory.getInstance().formatDate(order.getDate());
}
/**
* @return the date
*/
public String getDate() {
return this.date;
}
/**
* @param date
* the date to set
*/
public void setDate(String date) {
this.date = date;
}
/**
* @return the state
*/
public State getState() {
return this.state;
}
/**
* @param state
* the state to set
*/
public void setState(State state) {
this.state = state;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.date == null) ? 0 : this.date.hashCode());
result = prime * result + ((this.state == null) ? 0 : this.state.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OrderOverview other = (OrderOverview) obj;
if (this.date == null) {
if (other.date != null)
return false;
} else if (!this.date.equals(other.date))
return false;
if (this.state != other.state)
return false;
return true;
}
}

View File

@ -1,92 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Realm")
public class RealmDetail {
@XmlElement(name = "elementMaps")
private List<ElementMapsOverview> elementMapOverviews;
public RealmDetail() {
// no-arg constructor for JAXB
}
public RealmDetail(List<ElementMapsOverview> elementMapOverviews) {
this.elementMapOverviews = elementMapOverviews;
}
/**
* @return the elementMapOverviews
*/
public List<ElementMapsOverview> getElementMapOverviews() {
return this.elementMapOverviews;
}
/**
* @param elementMapOverviews
* the elementMapOverviews to set
*/
public void setElementMapOverviews(List<ElementMapsOverview> elementMapOverviews) {
this.elementMapOverviews = elementMapOverviews;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementMapOverviews == null) ? 0 : this.elementMapOverviews.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RealmDetail other = (RealmDetail) obj;
if (this.elementMapOverviews == null) {
if (other.elementMapOverviews != null)
return false;
} else if (!this.elementMapOverviews.equals(other.elementMapOverviews))
return false;
return true;
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("RealmDetail [elementMapOverviews=");
sb.append(this.elementMapOverviews);
sb.append("]");
return sb.toString();
}
}

View File

@ -1,117 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "RealmOverview")
public class RealmOverview {
@XmlAttribute(name = "realmName")
private String realmName;
@XmlAttribute(name = "size")
private long size;
public RealmOverview() {
// no-arg constructor for JAXB
}
/**
* @param realmName
* @param size
*/
public RealmOverview(String realmName, long size) {
this.realmName = realmName;
this.size = size;
}
/**
* @return the realmName
*/
public String getRealmName() {
return this.realmName;
}
/**
* @param realmName
* the realmName to set
*/
public void setRealmName(String realmName) {
this.realmName = realmName;
}
/**
* @return the size
*/
public long getSize() {
return this.size;
}
/**
* @param size
* the size to set
*/
public void setSize(long size) {
this.size = size;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.realmName == null) ? 0 : this.realmName.hashCode());
result = prime * result + (int) (this.size ^ (this.size >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RealmOverview other = (RealmOverview) obj;
if (this.realmName == null) {
if (other.realmName != null)
return false;
} else if (!this.realmName.equals(other.realmName))
return false;
if (this.size != other.size)
return false;
return true;
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("RealmOverview [realmName=");
sb.append(this.realmName);
sb.append(", size=");
sb.append(this.size);
sb.append("]");
return sb.toString();
}
}

View File

@ -1,50 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Resource")
public class ResourceOverview extends StrolchElementOverview {
public ResourceOverview() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
*/
public ResourceOverview(String id, String name, String type) {
super(id, name, type);
}
/**
* @param resource
*/
public ResourceOverview(Resource resource) {
super(resource);
}
}

View File

@ -1,144 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso({ ResourceOverview.class, OrderOverview.class })
public abstract class StrolchElementOverview {
@XmlAttribute(name = "id", required = true)
private String id;
@XmlAttribute(name = "name", required = true)
private String name;
@XmlAttribute(name = "type", required = true)
private String type;
public StrolchElementOverview() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
*/
public StrolchElementOverview(String id, String name, String type) {
this.id = id;
this.name = name;
this.type = type;
}
/**
* @param strolchElement
*/
public StrolchElementOverview(StrolchElement strolchElement) {
this.id = strolchElement.getId();
this.name = strolchElement.getName();
this.type = strolchElement.getType();
}
/**
* @return the id
*/
public String getId() {
return this.id;
}
/**
* @param id
* the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the type
*/
public String getType() {
return this.type;
}
/**
* @param type
* the type to set
*/
public void setType(String type) {
this.type = type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
StrolchElementOverview other = (StrolchElementOverview) obj;
if (this.id == null) {
if (other.id != null)
return false;
} else if (!this.id.equals(other.id))
return false;
if (this.name == null) {
if (other.name != null)
return false;
} else if (!this.name.equals(other.name))
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
}

View File

@ -1,114 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Types")
public class TypeDetail {
@XmlAttribute(name = "type")
private String type;
@XmlElements({ @XmlElement(name = "orders", type = OrderOverview.class),
@XmlElement(name = "resources", type = ResourceOverview.class) })
private List<StrolchElementOverview> elementOverviews;
public TypeDetail() {
// no-arg constructor for JAXB
}
/**
* @param type
* @param elementOverviews
*/
public TypeDetail(String type, List<StrolchElementOverview> elementOverviews) {
this.type = type;
this.elementOverviews = elementOverviews;
}
/**
* @return the type
*/
public String getType() {
return this.type;
}
/**
* @param type
* the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* @return the elementOverviews
*/
public List<StrolchElementOverview> getElementOverviews() {
return this.elementOverviews;
}
/**
* @param elementOverviews
* the elementOverviews to set
*/
public void setElementOverviews(List<StrolchElementOverview> elementOverviews) {
this.elementOverviews = elementOverviews;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementOverviews == null) ? 0 : this.elementOverviews.hashCode());
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TypeDetail other = (TypeDetail) obj;
if (this.elementOverviews == null) {
if (other.elementOverviews != null)
return false;
} else if (!this.elementOverviews.equals(other.elementOverviews))
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
}

View File

@ -1,113 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.model;
import java.text.MessageFormat;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Types")
public class TypeOverview {
@XmlAttribute(name = "type")
private String type;
@XmlAttribute(name = "size")
private long size;
public TypeOverview() {
// no-arg constructor for JAXB
}
/**
* @param type
* @param size
*/
public TypeOverview(String type, long size) {
this.type = type;
this.size = size;
}
/**
* @return the type
*/
public String getType() {
return this.type;
}
/**
* @param type
* the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* @return the size
*/
public long getSize() {
return this.size;
}
/**
* @param size
* the size to set
*/
public void setSize(long size) {
this.size = size;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (this.size ^ (this.size >>> 32));
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TypeOverview other = (TypeOverview) obj;
if (this.size != other.size)
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
@Override
public String toString() {
return MessageFormat.format("TypeOverview [type={0}, size={1}]", this.type, this.size); //$NON-NLS-1$
}
}

View File

@ -1,9 +1,9 @@
package li.strolch.rest.visitor;
import static li.strolch.model.Tags.ID;
import static li.strolch.model.Tags.NAME;
import static li.strolch.model.Tags.OBJECT_TYPE;
import static li.strolch.model.Tags.TYPE;
import static li.strolch.model.Tags.Json.ID;
import static li.strolch.model.Tags.Json.NAME;
import static li.strolch.model.Tags.Json.OBJECT_TYPE;
import static li.strolch.model.Tags.Json.TYPE;
import java.util.Collections;
import java.util.Set;

View File

@ -1,185 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.inspector.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import li.strolch.rest.model.AgentOverview;
import li.strolch.rest.model.ElementMapOverview;
import li.strolch.rest.model.ElementMapType;
import li.strolch.rest.model.ElementMapsOverview;
import li.strolch.rest.model.RealmDetail;
import li.strolch.rest.model.RealmOverview;
import li.strolch.rest.model.TypeOverview;
import org.junit.Ignore;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@SuppressWarnings("nls")
@Ignore
public class InspectorTest extends AbstractRestfulTest {
private static final String ROOT_PATH = "strolch/inspector/";
@Test
public void shouldGetAgent() {
Response response = target().path("/").request(MediaType.TEXT_HTML).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// expected result
List<RealmOverview> realms = new ArrayList<>(1);
realms.add(new RealmOverview("defaultRealm", 6));
AgentOverview expectedAgentOverview = new AgentOverview(realms);
// query
Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
AgentOverview agentOverview = result.readEntity(AgentOverview.class);
// assertions
assertEquals(expectedAgentOverview, agentOverview);
}
@Test
public void shouldGetRealm() {
// expected result
List<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2);
Set<String> resourceTypes = new HashSet<>();
resourceTypes.add("Template");
resourceTypes.add("TestType");
resourceTypes.add("Enumeration");
elementMapOverviews.add(new ElementMapsOverview(ElementMapType.RESOURCE, 4, resourceTypes));
Set<String> orderTypes = new HashSet<>();
orderTypes.add("Template");
orderTypes.add("TestType");
elementMapOverviews.add(new ElementMapsOverview(ElementMapType.ORDER, 2, orderTypes));
RealmDetail expectedRealmDetail = new RealmDetail(elementMapOverviews);
// query
Response result = target().path(ROOT_PATH + "defaultRealm").request(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
RealmDetail realmDetail = result.readEntity(RealmDetail.class);
// assertions
assertEquals(expectedRealmDetail, realmDetail);
}
@Test
public void shouldGetResourcesOverview() {
// expected result
String elementMapName = "Resource";
List<TypeOverview> typeOverviews = new ArrayList<>(2);
typeOverviews.add(new TypeOverview("Enumeration", 2));
typeOverviews.add(new TypeOverview("Template", 1));
typeOverviews.add(new TypeOverview("TestType", 1));
ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews);
// query
Response result = target().path(ROOT_PATH + "defaultRealm/resource").request(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
ElementMapOverview elementMapOverview = result.readEntity(ElementMapOverview.class);
// assertions
assertEquals(expectedElementMapOverview, elementMapOverview);
}
@Test
public void shouldGetOrdersOverview() {
// expected result
String elementMapName = "Order";
List<TypeOverview> typeOverviews = new ArrayList<>(2);
typeOverviews.add(new TypeOverview("Template", 1));
typeOverviews.add(new TypeOverview("TestType", 1));
ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews);
// query
Response result = target().path(ROOT_PATH + "defaultRealm/order").request(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
ElementMapOverview elementMapOverview = result.readEntity(ElementMapOverview.class);
// assertions
assertEquals(expectedElementMapOverview, elementMapOverview);
}
// TODO modify object model to include discriminator values, so that we can parse the objects
@Test
public void shouldGetResourceTypeDetails() {
// query
WebTarget target = target();
Response result = target.path(ROOT_PATH + "defaultRealm/resource/Template").request(MediaType.APPLICATION_JSON)
.get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
String entity = result.readEntity(String.class);
String expected = "{\"type\":\"Template\",\"resources\":[{\"id\":\"TestType\",\"name\":\"TestType Template\",\"type\":\"Template\"}]}";
assertEquals(expected, entity);
}
@Test
public void shouldGetOrderTypeDetails() {
// query
Response result = target().path(ROOT_PATH + "defaultRealm/order/Template").request(MediaType.APPLICATION_JSON)
.get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
String entity = result.readEntity(String.class);
String expected = "{\"type\":\"Template\",\"orders\":[{\"id\":\"TestType\",\"name\":\"MyTestOrder Template\",\"type\":\"Template\",\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\"}]}";
assertEquals(expected, entity);
}
@Test
public void shouldGetResource() {
// query
Response result = target().path(ROOT_PATH + "defaultRealm/resource/Template/TestType")
.request(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
String entity = result.readEntity(String.class);
assertTrue(entity.contains("name\":\"TestType Template\",\"type\":\"Template\",\"parameterBags\":"));
}
@Test
public void shouldGetOrder() {
// query
Response result = target().path(ROOT_PATH + "defaultRealm/order/Template/TestType")
.request(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), result.getStatus());
String entity = result.readEntity(String.class);
assertTrue(entity
.contains("\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\",\"parameterBags\""));
}
}