Skip to content

Commit

Permalink
Add support for resolveNames REST option
Browse files Browse the repository at this point in the history
This is to support showing archetype names in Eclipse plugin (MID-4665).
  • Loading branch information
mederly committed May 2, 2019
1 parent 8ceed9f commit 42d6293
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Expand Up @@ -946,11 +946,11 @@ public void shortDump(StringBuilder sb) {
removeLastComma(sb);
}


public static Collection<SelectorOptions<GetOperationOptions>> fromRestOptions(List<String> options, List<String> include,
List<String> exclude, DefinitionProcessingOption definitionProcessing,
List<String> exclude, List<String> resolveNames, DefinitionProcessingOption definitionProcessing,
PrismContext prismContext) {
if (CollectionUtils.isEmpty(options) && CollectionUtils.isEmpty(include) && CollectionUtils.isEmpty(exclude)) {
if (CollectionUtils.isEmpty(options) && CollectionUtils.isEmpty(include) && CollectionUtils.isEmpty(exclude)
&& CollectionUtils.isEmpty(resolveNames)) {
if (definitionProcessing != null) {
return SelectorOptions.createCollection(GetOperationOptions.createDefinitionProcessing(definitionProcessing));
}
Expand All @@ -967,12 +967,15 @@ public static Collection<SelectorOptions<GetOperationOptions>> fromRestOptions(L
for (ItemPath excludePath : ItemPathCollectionsUtil.pathListFromStrings(exclude, prismContext)) {
rv.add(SelectorOptions.create(prismContext.toUniformPath(excludePath), GetOperationOptions.createDontRetrieve()));
}
for (ItemPath resolveNamesPath : ItemPathCollectionsUtil.pathListFromStrings(resolveNames, prismContext)) {
rv.add(SelectorOptions.create(prismContext.toUniformPath(resolveNamesPath), GetOperationOptions.createResolveNames()));
}
// Do NOT set executionPhase here!
return rv;
}

public static GetOperationOptions fromRestOptions(List<String> options, DefinitionProcessingOption definitionProcessing) {
if (options == null || options.isEmpty()){
if (options == null || options.isEmpty()) {
if (definitionProcessing != null) {
return GetOperationOptions.createDefinitionProcessing(definitionProcessing);
}
Expand Down
Expand Up @@ -326,15 +326,16 @@ public Response getObject(@PathParam("type") String type, @PathParam("id") Strin
@QueryParam("options") List<String> options,
@QueryParam("include") List<String> include,
@QueryParam("exclude") List<String> exclude,
@QueryParam("resolveNames") List<String> resolveNames,
@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<? extends ObjectType> clazz = ObjectTypes.getClassFromRestType(type);
Collection<SelectorOptions<GetOperationOptions>> getOptions = GetOperationOptions.fromRestOptions(options, include, exclude, DefinitionProcessingOption.ONLY_IF_EXISTS,
prismContext);
Collection<SelectorOptions<GetOperationOptions>> getOptions = GetOperationOptions.fromRestOptions(options, include,
exclude, resolveNames, DefinitionProcessingOption.ONLY_IF_EXISTS, prismContext);
Response response;

try {
Expand Down Expand Up @@ -456,6 +457,7 @@ public <T extends ObjectType> Response addObject(@PathParam("type") String type,
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, RestServiceUtil.APPLICATION_YAML})
public <T extends ObjectType> Response searchObjectsByType(@PathParam("type") String type, @QueryParam("options") List<String> options,
@QueryParam("include") List<String> include, @QueryParam("exclude") List<String> exclude,
@QueryParam("resolveNames") List<String> resolveNames,
@Context UriInfo uriInfo, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SEARCH_OBJECTS);
Expand All @@ -465,8 +467,8 @@ public <T extends ObjectType> Response searchObjectsByType(@PathParam("type") St
Response response;
try {

Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, include, exclude, DefinitionProcessingOption.ONLY_IF_EXISTS,
prismContext);
Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, include,
exclude, resolveNames, DefinitionProcessingOption.ONLY_IF_EXISTS, prismContext);

List<PrismObject<T>> objects = modelService.searchObjects(clazz, null, searchOptions, task, parentResult);
ObjectListType listType = new ObjectListType();
Expand Down Expand Up @@ -723,7 +725,8 @@ public Response searchObjects(@PathParam("type") String type, QueryType queryTyp
@QueryParam("options") List<String> options,
@QueryParam("include") List<String> include,
@QueryParam("exclude") List<String> exclude,
@Context MessageContext mc){
@QueryParam("resolveNames") List<String> resolveNames,
@Context MessageContext mc) {

Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_SEARCH_OBJECTS);
Expand All @@ -732,8 +735,8 @@ public Response searchObjects(@PathParam("type") String type, QueryType queryTyp
Response response;
try {
ObjectQuery query = prismContext.getQueryConverter().createObjectQuery(clazz, queryType);
Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, include, exclude, DefinitionProcessingOption.ONLY_IF_EXISTS,
prismContext);
Collection<SelectorOptions<GetOperationOptions>> searchOptions = GetOperationOptions.fromRestOptions(options, include,
exclude, resolveNames, DefinitionProcessingOption.ONLY_IF_EXISTS, prismContext);
List<PrismObject<? extends ObjectType>> objects = model.searchObjects(clazz, query, searchOptions, task, parentResult);

ObjectListType listType = new ObjectListType();
Expand Down

0 comments on commit 42d6293

Please sign in to comment.