use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ModelWebService method getObject.
@Override
public void getObject(QName objectType, String oid, SelectorQualifiedGetOptionsType optionsType, Holder<ObjectType> objectHolder, Holder<OperationResultType> resultHolder) throws FaultMessage {
notNullArgument(objectType, "Object type must not be null.");
notEmptyArgument(oid, "Oid must not be null or empty.");
Task task = createTaskInstance(GET_OBJECT);
auditLogin(task);
OperationResult operationResult = task.getResult();
try {
Class objectClass = ObjectTypes.getObjectTypeFromTypeQName(objectType).getClassDefinition();
Collection<SelectorOptions<GetOperationOptions>> options = MiscSchemaUtil.optionsTypeToOptions(optionsType);
PrismObject<? extends ObjectType> object = model.getObject(objectClass, oid, options, task, operationResult);
handleOperationResult(operationResult, resultHolder);
objectHolder.value = object.asObjectable();
return;
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "# MODEL getObject() failed", ex);
throwFault(ex, operationResult);
} finally {
auditLogout(task);
}
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ModelWebService method searchObjects.
@Override
public void searchObjects(QName objectType, QueryType query, SelectorQualifiedGetOptionsType optionsType, Holder<ObjectListType> objectListHolder, Holder<OperationResultType> result) throws FaultMessage {
notNullArgument(objectType, "Object type must not be null.");
Task task = createTaskInstance(SEARCH_OBJECTS);
auditLogin(task);
OperationResult operationResult = task.getResult();
try {
Class objectClass = ObjectTypes.getObjectTypeFromTypeQName(objectType).getClassDefinition();
Collection<SelectorOptions<GetOperationOptions>> options = MiscSchemaUtil.optionsTypeToOptions(optionsType);
ObjectQuery q = QueryJaxbConvertor.createObjectQuery(objectClass, query, prismContext);
List<PrismObject<? extends ObjectType>> list = (List) model.searchObjects(objectClass, q, options, task, operationResult);
handleOperationResult(operationResult, result);
ObjectListType listType = new ObjectListType();
for (PrismObject<? extends ObjectType> o : list) {
listType.getObject().add(o.asObjectable());
}
objectListHolder.value = listType;
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "# MODEL searchObjects() failed", ex);
throwFault(ex, operationResult);
} finally {
auditLogout(task);
}
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ModelRestService method searchObjects.
@POST
@Path("/{type}/search")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public Response searchObjects(@PathParam("type") String type, QueryType queryType, @QueryParam("options") List<String> options, @QueryParam("include") List<String> include, @QueryParam("exclude") List<String> exclude, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SEARCH_OBJECTS);
Class clazz = ObjectTypes.getClassFromRestType(type);
Response response;
try {
ObjectQuery query = QueryJaxbConvertor.createObjectQuery(clazz, queryType, prismContext);
Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, include, exclude);
List<PrismObject<? extends ObjectType>> objects = model.searchObjects(clazz, query, searchOptions, task, parentResult);
ObjectListType listType = new ObjectListType();
for (PrismObject<? extends ObjectType> o : objects) {
// temporary measure until fixed in repo
removeExcludes(o, exclude);
listType.getObject().add(o.asObjectable());
}
// response = Response.ok().entity(listType).build();
response = RestServiceUtil.createResponse(Response.Status.OK, listType, parentResult, true);
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
parentResult.computeStatus();
finishRequest(task);
return response;
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ModelRestService method searchObjectsByType.
@GET
@Path("/{type}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public <T extends ObjectType> Response searchObjectsByType(@PathParam("type") String type, @QueryParam("options") List<String> options, @Context UriInfo uriInfo, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SEARCH_OBJECTS);
Class<T> clazz = ObjectTypes.getClassFromRestType(type);
Response response;
try {
Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, null, null);
List<PrismObject<T>> objects = model.searchObjects(clazz, null, searchOptions, task, parentResult);
ObjectListType listType = new ObjectListType();
if (objects != null) {
List<ObjectType> list = objects.stream().map(o -> convert(clazz, o, parentResult.createOperationResultType())).collect(Collectors.toList());
listType.getObject().addAll(list);
}
response = RestServiceUtil.createResponse(Response.Status.OK, listType, parentResult, true);
// response = Response.ok().entity(listType).build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
parentResult.computeStatus();
finishRequest(task);
return response;
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ModelRestService method getObject.
@GET
@Path("/{type}/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public <T extends ObjectType> Response getObject(@PathParam("type") String type, @PathParam("id") String id, @QueryParam("options") List<String> options, @QueryParam("include") List<String> include, @QueryParam("exclude") List<String> exclude, @Context MessageContext mc) {
LOGGER.debug("model rest service for get operation start");
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_GET);
Class<T> clazz = ObjectTypes.getClassFromRestType(type);
Collection<SelectorOptions<GetOperationOptions>> getOptions = GetOperationOptions.fromRestOptions(options, include, exclude);
Response response;
try {
PrismObject<T> object;
if (NodeType.class.equals(clazz) && CURRENT.equals(id)) {
String nodeId = taskManager.getNodeId();
ObjectQuery query = QueryBuilder.queryFor(NodeType.class, prismContext).item(NodeType.F_NODE_IDENTIFIER).eq(nodeId).build();
List<PrismObject<NodeType>> objects = model.searchObjects(NodeType.class, query, getOptions, task, parentResult);
if (objects.isEmpty()) {
throw new ObjectNotFoundException("Current node (id " + nodeId + ") couldn't be found.");
} else if (objects.size() > 1) {
throw new IllegalStateException("More than one 'current' node (id " + nodeId + ") found.");
} else {
object = (PrismObject<T>) objects.get(0);
}
} else {
object = model.getObject(clazz, id, getOptions, task, parentResult);
}
// temporary measure until fixed in repo
removeExcludes(object, exclude);
response = RestServiceUtil.createResponse(Response.Status.OK, object, parentResult);
// ResponseBuilder builder = Response.ok();
// builder.entity(object);
// response = builder.build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
parentResult.computeStatus();
finishRequest(task);
return response;
}
Aggregations