[New] Now also showing activities in model view
This commit is contained in:
parent
cac24481ee
commit
454b36d659
|
@ -15,7 +15,8 @@ strolch.const = {
|
||||||
auth: 'rest/strolch/authentication',
|
auth: 'rest/strolch/authentication',
|
||||||
version: 'rest/strolch/version',
|
version: 'rest/strolch/version',
|
||||||
resources: 'rest/strolch/model/resources',
|
resources: 'rest/strolch/model/resources',
|
||||||
orders: 'rest/strolch/model/orders'
|
orders: 'rest/strolch/model/orders',
|
||||||
|
activities: 'rest/strolch/model/activities'
|
||||||
},
|
},
|
||||||
|
|
||||||
auth_token: 'auth_token',
|
auth_token: 'auth_token',
|
||||||
|
|
|
@ -21,6 +21,7 @@ strolch.parts.model.init = function (domParent) {
|
||||||
|
|
||||||
strolch.parts.model.prepareResourceTable();
|
strolch.parts.model.prepareResourceTable();
|
||||||
strolch.parts.model.prepareOrderTable();
|
strolch.parts.model.prepareOrderTable();
|
||||||
|
strolch.parts.model.prepareActivityTable();
|
||||||
|
|
||||||
strolch.parts.model.registerHandlers();
|
strolch.parts.model.registerHandlers();
|
||||||
};
|
};
|
||||||
|
@ -81,3 +82,20 @@ strolch.parts.model.prepareOrderTable = function () {
|
||||||
|
|
||||||
strolch.fn.initDataTable(data, columns);
|
strolch.fn.initDataTable(data, columns);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
strolch.parts.model.prepareActivityTable = function () {
|
||||||
|
|
||||||
|
// prepare query data
|
||||||
|
var data = strolch.fn.dataTableDefaults();
|
||||||
|
data.realmName = '';
|
||||||
|
data.url = strolch.fn.url(strolch.const.urls.activities);
|
||||||
|
data.tableId = 'modelActivityTable';
|
||||||
|
data.searchFieldId = 'modelActivityTableSearch';
|
||||||
|
|
||||||
|
var columns = [];
|
||||||
|
columns.push({title: 'Id', width: 50, data: 'Id'});
|
||||||
|
columns.push({title: 'Name', data: 'Name'});
|
||||||
|
columns.push({title: 'Type', data: 'Type'});
|
||||||
|
|
||||||
|
strolch.fn.initDataTable(data, columns);
|
||||||
|
};
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#model-ordersTab" role="tab">Orders</a>
|
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#model-ordersTab" role="tab">Orders</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#model-activitiesTab" role="tab">Activities</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
|
@ -58,6 +60,28 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane" id="model-activitiesTab" role="tabpanel">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<form>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-sm-offset-2 col-sm-8">
|
||||||
|
<input type="text" class="form-control" id="modelActivityTableSearch"
|
||||||
|
placeholder="[id:<value>] [name:<value>] [type:<value>] [param:<bagId>:<paramId>] [value]">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<table id="modelActivityTable" class="table table-striped table-bordered hover" cellspacing="0"
|
||||||
|
width="100%">
|
||||||
|
|
||||||
|
<caption>The activities for the current user's realm</caption>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,6 +11,8 @@ import org.petitparser.tools.CompositeParser;
|
||||||
import ch.eitchnet.utils.StringMatchMode;
|
import ch.eitchnet.utils.StringMatchMode;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.model.query.ActivityQuery;
|
||||||
import li.strolch.model.query.IdSelection;
|
import li.strolch.model.query.IdSelection;
|
||||||
import li.strolch.model.query.NameSelection;
|
import li.strolch.model.query.NameSelection;
|
||||||
import li.strolch.model.query.OrSelection;
|
import li.strolch.model.query.OrSelection;
|
||||||
|
@ -18,6 +20,7 @@ import li.strolch.model.query.OrderQuery;
|
||||||
import li.strolch.model.query.ResourceQuery;
|
import li.strolch.model.query.ResourceQuery;
|
||||||
import li.strolch.model.query.StrolchElementQuery;
|
import li.strolch.model.query.StrolchElementQuery;
|
||||||
import li.strolch.model.query.StrolchTypeNavigation;
|
import li.strolch.model.query.StrolchTypeNavigation;
|
||||||
|
import li.strolch.model.visitor.NoStrategyActivityVisitor;
|
||||||
import li.strolch.model.visitor.NoStrategyOrderVisitor;
|
import li.strolch.model.visitor.NoStrategyOrderVisitor;
|
||||||
import li.strolch.model.visitor.NoStrategyResourceVisitor;
|
import li.strolch.model.visitor.NoStrategyResourceVisitor;
|
||||||
|
|
||||||
|
@ -118,4 +121,17 @@ public class QueryParser extends CompositeParser {
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ActivityQuery<Activity> parseToActivityQuery(String queryString, boolean withAny) {
|
||||||
|
QueryParser parser = new QueryParser(new ActivityQuery<>());
|
||||||
|
Result result = parser.parse(queryString);
|
||||||
|
ActivityQuery<Activity> query = result.get();
|
||||||
|
query.setActivityVisitor(new NoStrategyActivityVisitor());
|
||||||
|
|
||||||
|
if (!query.hasSelection() && withAny) {
|
||||||
|
query.withAny();
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,18 @@ import com.google.gson.JsonObject;
|
||||||
import ch.eitchnet.privilege.model.Certificate;
|
import ch.eitchnet.privilege.model.Certificate;
|
||||||
import ch.eitchnet.utils.collections.Paging;
|
import ch.eitchnet.utils.collections.Paging;
|
||||||
import ch.eitchnet.utils.helper.StringHelper;
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.StrolchRootElement;
|
import li.strolch.model.StrolchRootElement;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.model.json.ActivityToJsonVisitor;
|
||||||
import li.strolch.model.json.OrderToJsonVisitor;
|
import li.strolch.model.json.OrderToJsonVisitor;
|
||||||
import li.strolch.model.json.ResourceToJsonVisitor;
|
import li.strolch.model.json.ResourceToJsonVisitor;
|
||||||
|
import li.strolch.model.query.ActivityQuery;
|
||||||
import li.strolch.model.query.OrderQuery;
|
import li.strolch.model.query.OrderQuery;
|
||||||
import li.strolch.model.query.ResourceQuery;
|
import li.strolch.model.query.ResourceQuery;
|
||||||
import li.strolch.model.query.StrolchTypeNavigation;
|
import li.strolch.model.query.StrolchTypeNavigation;
|
||||||
|
@ -164,64 +168,64 @@ public class ModelQuery {
|
||||||
return Response.ok(entity).build();
|
return Response.ok(entity).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Query {@link Activity Activities} by parsing the query string in {@link QueryData#getQuery()} using
|
* Query {@link Activity Activities} by parsing the query string in {@link QueryData#getQuery()} using
|
||||||
// * {@link QueryParser}
|
* {@link QueryParser}
|
||||||
// *
|
*
|
||||||
// * @param queryData
|
* @param queryData
|
||||||
// * the data from the client
|
* the data from the client
|
||||||
// * @param request
|
* @param request
|
||||||
// * the {@link HttpServletRequest} on which to get the {@link Certificate}
|
* the {@link HttpServletRequest} on which to get the {@link Certificate}
|
||||||
// *
|
*
|
||||||
// * @return {@link Response} containing the JSONified {@link Activity Activities} queried
|
* @return {@link Response} containing the JSONified {@link Activity Activities} queried
|
||||||
// */
|
*/
|
||||||
// @GET
|
@GET
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
// @Path("orders")
|
@Path("activities")
|
||||||
// public Response queryActivities(@BeanParam QueryData queryData, @Context HttpServletRequest request) {
|
public Response queryActivities(@BeanParam QueryData queryData, @Context HttpServletRequest request) {
|
||||||
// Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||||
//
|
|
||||||
// // see if a special realm was requested
|
// see if a special realm was requested
|
||||||
// String realmName = getRealmName(queryData);
|
String realmName = getRealmName(queryData);
|
||||||
//
|
|
||||||
// List<Activity> activities = new ArrayList<>();
|
List<Activity> activities = new ArrayList<>();
|
||||||
//
|
|
||||||
// // parse the query string
|
// parse the query string
|
||||||
// ActivityQuery<Activity> query = QueryParser.parseToActivityQuery(queryData.getQuery(), true);
|
ActivityQuery<Activity> query = QueryParser.parseToActivityQuery(queryData.getQuery(), true);
|
||||||
//
|
|
||||||
// // query the data
|
// query the data
|
||||||
// long dataSetSize = 0L;
|
long dataSetSize = 0L;
|
||||||
// try (StrolchTransaction tx = openTx(cert, realmName)) {
|
try (StrolchTransaction tx = openTx(cert, realmName)) {
|
||||||
// ActivityMap activityMap = tx.getActivityMap();
|
ActivityMap activityMap = tx.getActivityMap();
|
||||||
//
|
|
||||||
// if (query.hasNavigation()) {
|
if (query.hasNavigation()) {
|
||||||
// String type = ((StrolchTypeNavigation) query.getNavigation()).getType();
|
String type = ((StrolchTypeNavigation) query.getNavigation()).getType();
|
||||||
// dataSetSize = activityMap.querySize(tx, type);
|
dataSetSize = activityMap.querySize(tx, type);
|
||||||
// activities.addAll(tx.doQuery(query));
|
activities.addAll(tx.doQuery(query));
|
||||||
// } else {
|
} else {
|
||||||
// Set<String> types = activityMap.getTypes(tx);
|
Set<String> types = activityMap.getTypes(tx);
|
||||||
// dataSetSize = activityMap.querySize(tx);
|
dataSetSize = activityMap.querySize(tx);
|
||||||
// for (String type : types) {
|
for (String type : types) {
|
||||||
// query.setNavigation(new StrolchTypeNavigation(type));
|
query.setNavigation(new StrolchTypeNavigation(type));
|
||||||
// activities.addAll(tx.doQuery(query));
|
activities.addAll(tx.doQuery(query));
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// tx.doNothingOnClose();
|
tx.doNothingOnClose();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // do ordering
|
// do ordering
|
||||||
// doOrdering(queryData, activities);
|
doOrdering(queryData, activities);
|
||||||
//
|
|
||||||
// // build JSON response
|
// build JSON response
|
||||||
// ActivityToJsonVisitor toJsonVisitor = new ActivityToJsonVisitor();
|
ActivityToJsonVisitor toJsonVisitor = new ActivityToJsonVisitor();
|
||||||
// JsonObject root = marshall(queryData, dataSetSize, activities, toJsonVisitor);
|
JsonObject root = marshall(queryData, dataSetSize, activities, toJsonVisitor);
|
||||||
//
|
|
||||||
// // marshall result
|
// marshall result
|
||||||
// Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
// String entity = gson.toJson(root);
|
String entity = gson.toJson(root);
|
||||||
// return Response.ok(entity).build();
|
return Response.ok(entity).build();
|
||||||
// }
|
}
|
||||||
|
|
||||||
private <T extends StrolchRootElement> JsonObject marshall(QueryData queryData, long dataSetSize, List<T> elements,
|
private <T extends StrolchRootElement> JsonObject marshall(QueryData queryData, long dataSetSize, List<T> elements,
|
||||||
StrolchElementVisitor<T, JsonObject> toJsonVisitor) {
|
StrolchElementVisitor<T, JsonObject> toJsonVisitor) {
|
||||||
|
|
Loading…
Reference in New Issue