use of com.manydesigns.portofino.security.RequiresPermissions in project Portofino by ManyDesigns.
the class ManyToManyAction method httpPostJson.
/**
* Handles object creation via REST.
* @param jsonObject the object (in serialized JSON form)
* @since 4.2.1
* @return the created object as JSON (in a JAX-RS Response).
* @throws Exception only to make the compiler happy. Nothing should be thrown in normal operation. If this method throws, it is probably a bug.
*/
@POST
@RequiresPermissions(permissions = ManyToManyAction.PERMISSION_UPDATE)
@Produces(MimeTypes.APPLICATION_JSON_UTF8)
@Consumes(MimeTypes.APPLICATION_JSON_UTF8)
public Response httpPostJson(String jsonObject) throws Exception {
JSONObject obj = new JSONObject(jsonObject);
logger.debug(jsonObject);
if (!correctlyConfigured) {
return Response.serverError().entity(configurationForm).build();
}
for (Object key : obj.keySet()) {
try {
loadOnePk(key);
} catch (Exception e) {
logger.error("Cannot get key " + key, e);
}
JSONArray selectedKeysJson = obj.getJSONArray(onePk.toString());
for (int i = 0; i < selectedKeysJson.length(); i++) {
selectedPrimaryKeys.add(selectedKeysJson.get(i).toString());
}
try {
loadAssociations();
} catch (Exception e) {
logger.error("Could not load associations", e);
return Response.serverError().entity(e).build();
}
// TODO chiave multipla
String onePropertyName = m2mConfiguration.getActualOnePropertyName();
PropertyAccessor onePropertyAccessor = relationTableAccessor.getProperty(onePropertyName);
// TODO chiave multipla
String manyPropertyName = m2mConfiguration.getManySelectionProvider().getActualSelectionProvider().getReferences().get(0).getActualFromColumn().getActualPropertyName();
PropertyAccessor manyPropertyAccessor = relationTableAccessor.getProperty(manyPropertyName);
PropertyAccessor[] manyKeyProperties = manyTableAccessor.getKeyProperties();
// TODO handle manyKeyProperties.length > 1
PropertyAccessor manyPkAccessor = manyTableAccessor.getProperty(manyKeyProperties[0].getName());
for (String pkString : selectedPrimaryKeys) {
Object pkObject = manyTableAccessor.getIdStrategy().getPrimaryKey(pkString.split("/"));
Object pk = manyPkAccessor.get(pkObject);
if (!isExistingAssociation(manyPropertyAccessor, pk)) {
Object newRelation = saveNewRelation(pk, onePropertyAccessor, manyPropertyAccessor);
existingAssociations.add(newRelation);
}
}
Iterator it = existingAssociations.iterator();
while (it.hasNext()) {
Object o = it.next();
// TODO handle manyKeyProperties.length > 1
Object pkObject = manyPropertyAccessor.get(o);
String pkString = OgnlUtils.convertValue(pkObject, String.class);
if (!selectedPrimaryKeys.contains(pkString)) {
deleteRelation(o);
it.remove();
}
}
}
session.getTransaction().commit();
return objectCreated();
}
use of com.manydesigns.portofino.security.RequiresPermissions in project Portofino by ManyDesigns.
the class ActionsAction method getResourceActionTypes.
@Path(":types")
@GET
@RequiresPermissions(level = AccessLevel.NONE)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, ActionTypeInfo> getResourceActionTypes() {
Map<String, ActionTypeInfo> result = new HashMap<>();
TextProvider textProvider = ElementsThreadLocals.getTextProvider();
actionRegistry.iterator().forEachRemaining(a -> {
String className = a.actionClass.getName();
result.put(a.description, new ActionTypeInfo(className, a.getActionName(textProvider), textProvider.getTextOrNull(className + ".description"), a.supportsDetail));
});
return result;
}
Aggregations