Java Code Examples for javax.ws.rs.core.MultivaluedMap#isEmpty()

The following examples show how to use javax.ws.rs.core.MultivaluedMap#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FHIRClientImpl.java    From FHIR with Apache License 2.0 6 votes vote down vote up
/**
 * This function adds each of the parameters contained in the FHIRParameters object to the specified WebTarget as a
 * query parameter.
 *
 * @param endpoint
 *            the WebTarget which will receive the query parameters
 * @param parameters
 *            the FHIRParameters object that contains the query parameters to be added
 */
private WebTarget addParametersToWebTarget(WebTarget endpoint, FHIRParameters parameters) {
    if (parameters != null) {
        MultivaluedMap<String, String> parameterMap = parameters.getParameterMap();
        if (parameterMap != null && !parameterMap.isEmpty()) {

            // Each entry in the multivalued map represents a query parameter and its value(s).
            // So for each entry, we'll add a query parameter to the WebTarget
            for (Map.Entry<String, List<String>> mapEntry : parameterMap.entrySet()) {
                for (String value : mapEntry.getValue()) {
                    endpoint = endpoint.queryParam(mapEntry.getKey(), value);
                }
            }
        }
    }

    return endpoint;
}
 
Example 2
Source File: NotifierInfoCatalogResource.java    From streamline with Apache License 2.0 6 votes vote down vote up
/**
 * List ALL notifiers or the ones matching specific query params.
 */
@GET
@Path("/notifiers")
@Timed
public Response listNotifiers(@Context UriInfo uriInfo, @Context SecurityContext securityContext) {
    List<QueryParam> queryParams = new ArrayList<>();
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    Collection<Notifier> notifiers;
    if (params.isEmpty()) {
        notifiers = catalogService.listNotifierInfos();
    } else {
        queryParams = WSUtils.buildQueryParameters(params);
        notifiers = catalogService.listNotifierInfos(queryParams);
    }
    if (notifiers != null) {
        boolean notifierUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_USER);
        if (notifierUser) {
            LOG.debug("Returning all Notifiers since user has role: {}", Roles.ROLE_NOTIFIER_USER);
        } else {
            notifiers = SecurityUtil.filter(authorizer, securityContext, Notifier.NAMESPACE, notifiers, READ);
        }
        return WSUtils.respondEntities(notifiers, OK);
    }

    throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 3
Source File: SecurityCatalogResource.java    From streamline with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/acls")
@Timed
public Response listAcls(@Context UriInfo uriInfo,
                         @Context SecurityContext securityContext) throws Exception {
    Collection<AclEntry> acls;
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    List<QueryParam> queryParams = WSUtils.buildQueryParameters(params);
    if (params == null || params.isEmpty()) {
        acls = catalogService.listAcls();
    } else {
        acls = catalogService.listAcls(queryParams);
    }
    if (acls != null) {
        return WSUtils.respondEntities(filter(acls, securityContext), OK);
    }
    throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 4
Source File: RestTracerAdapter.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * Decode baggage items from response headers to invoke context
 *
 * @param headers response headers
 */
private static void decodeBaggageItemsFromResponse(MultivaluedMap<String, String> headers) {
    if (!RpcInvokeContext.isBaggageEnable() || headers == null || headers.isEmpty()) {
        return;
    }

    Map<String, String> baggageItems = new LinkedHashMap<String, String>();
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        if (!entry.getKey().startsWith(RPC_RESPONSE_BAGGAGE_PREFIX) ||
            entry.getValue() == null ||
            entry.getValue().isEmpty()) {
            continue;
        }

        String key = entry.getKey().substring(RPC_RESPONSE_BAGGAGE_PREFIX_LEN);
        String value = entry.getValue().get(0);
        baggageItems.put(key, value);
    }

    RpcInvokeContext.getContext().putAllResponseBaggage(baggageItems);
}
 
Example 5
Source File: SecurityCatalogResource.java    From streamline with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/users")
@Timed
public Response listUsers(@Context UriInfo uriInfo,
                          @Context SecurityContext securityContext) throws Exception {
    if (!SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN)) {
        LOG.debug("Allowing logged-in user '{}'", SecurityUtil.getUserName(securityContext.getUserPrincipal().getName()));
    }
    Collection<User> users;
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    List<QueryParam> queryParams = WSUtils.buildQueryParameters(params);
    if (params == null || params.isEmpty()) {
        users = catalogService.listUsers();
    } else {
        users = catalogService.listUsers(queryParams);
    }
    if (users != null) {
        return WSUtils.respondEntities(users, OK);
    }
    throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 6
Source File: NotificationsResource.java    From streamline with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/notifications/")
@Timed
public Response listNotifications(@Context UriInfo uriInfo, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFICATION_USER);
    List<QueryParam> queryParams = new ArrayList<>();
    MultivaluedMap<String, String> uriInfoParams = uriInfo.getQueryParameters();
    Collection<Notification> notifications = null;
    if (!uriInfoParams.isEmpty()) {
        queryParams = WSUtils.buildQueryParameters(uriInfoParams);
    } else {
        LOG.info("Query params empty, will use default criteria to return notifications.");
    }
    notifications = notificationService.findNotifications(queryParams);
    if (notifications != null && !notifications.isEmpty()) {
        return WSUtils.respondEntities(notifications, OK);
    }

    throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 7
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Builds param string for matrix part of URI.
 *
 * @param sb buffer to add the matrix part to, will get ';' added if map is not empty
 * @param map matrix multivalued map
 */
private void buildMatrix(StringBuilder sb, MultivaluedMap<String, String> map) {
    if (!map.isEmpty()) {
        sb.append(';');
        sb.append(buildParams(map, ';'));
    }
}
 
Example 8
Source File: FileCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/files")
@Timed
public Response listFiles(@Context UriInfo uriInfo,
                          @Context SecurityContext securityContext) {
    Collection<File> files = null;
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    if (params == null || params.isEmpty()) {
        files = catalogService.listFiles();
    } else {
        files = catalogService.listFiles(WSUtils.buildQueryParameters(params));
    }
    Collection<File> result = SecurityUtil.filter(authorizer, securityContext, File.NAMESPACE, files, READ);
    return WSUtils.respondEntities(result, OK);
}
 
Example 9
Source File: ParaClient.java    From para with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> find(String queryType, MultivaluedMap<String, String> params) {
	Map<String, Object> map = new HashMap<>();
	if (params != null && !params.isEmpty()) {
		String qType = StringUtils.isBlank(queryType) ? "/default" : "/".concat(queryType);
		if (StringUtils.isBlank(params.getFirst(Config._TYPE))) {
			return getEntity(invokeGet("search" + qType, params), Map.class);
		} else {
			return getEntity(invokeGet(params.getFirst(Config._TYPE) + "/search" + qType, params), Map.class);
		}
	} else {
		map.put("items", Collections.emptyList());
		map.put("totalHits", 0);
	}
	return map;
}
 
Example 10
Source File: DashboardCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
public static List<QueryParam> buildDashboardIdAwareQueryParams(Long dashboardId, UriInfo uriInfo) {
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(Dashboard.DASHBOARD_ID, dashboardId.toString()));
    if (uriInfo != null) {
        MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
        if (!params.isEmpty()) {
            queryParams.addAll(WSUtils.buildQueryParameters(params));
        }
    }
    return queryParams;
}
 
Example 11
Source File: ComponentCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
private List<QueryParam> buildServiceIdAwareQueryParams(Long serviceId, UriInfo uriInfo) {
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam("serviceId", serviceId.toString()));
    if (uriInfo != null) {
        MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
        if (!params.isEmpty()) {
            queryParams.addAll(WSUtils.buildQueryParameters(params));
        }
    }

    return queryParams;
}
 
Example 12
Source File: WorkflowVariablesTransformer.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public Map<String, String> getWorkflowVariablesFromPathSegment(PathSegment pathSegment) {
    Map<String, String> variables = null;
    MultivaluedMap<String, String> matrixParams = pathSegment.getMatrixParameters();
    if (matrixParams != null && !matrixParams.isEmpty()) {
        // Remove any empty keys that might be mistakenly sent to the scheduler to prevent bad behaviour
        matrixParams.remove("");
        variables = Maps.newHashMap();
        for (String key : matrixParams.keySet()) {
            String value = matrixParams.getFirst(key) == null ? "" : matrixParams.getFirst(key);
            variables.put(key, value);
        }
    }
    return variables;
}
 
Example 13
Source File: AtlasBaseClient.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private WebResource appendQueryParams(MultivaluedMap<String, String> queryParams, WebResource resource) {
    if (null != queryParams && !queryParams.isEmpty()) {
        for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
            for (String value : entry.getValue()) {
                if (StringUtils.isNotBlank(value)) {
                    resource = resource.queryParam(entry.getKey(), value);
                }
            }
        }
    }
    return resource;
}
 
Example 14
Source File: ServiceConfigurationCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
private List<QueryParam> buildServiceIdAwareQueryParams(Long serviceId, UriInfo uriInfo) {
    List<QueryParam> queryParams = new ArrayList<QueryParam>();
    queryParams.add(new QueryParam("serviceId", serviceId.toString()));
    if (uriInfo != null) {
        MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
        if (!params.isEmpty()) {
            queryParams.addAll(WSUtils.buildQueryParameters(params));
        }
    }

    return queryParams;
}
 
Example 15
Source File: NamespaceCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/namespaces")
@Timed
public Response listNamespaces(@Context UriInfo uriInfo,
                               @Context SecurityContext securityContext) {
  List<QueryParam> queryParams = new ArrayList<>();
  MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
  Collection<Namespace> namespaces;
  Boolean detail = false;

  if (params.isEmpty()) {
    namespaces = environmentService.listNamespaces();
  } else {
    MultivaluedMap<String, String> copiedParams = new MultivaluedHashMap<>();
    copiedParams.putAll(params);
    List<String> detailOption = copiedParams.remove("detail");
    if (detailOption != null && !detailOption.isEmpty()) {
      detail = BooleanUtils.toBooleanObject(detailOption.get(0));
    }

    queryParams = WSUtils.buildQueryParameters(copiedParams);
    namespaces = environmentService.listNamespaces(queryParams);
  }
  if (namespaces != null) {
    boolean environmentUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_USER);
    if (environmentUser) {
      LOG.debug("Returning all environments since user has role: {}", Roles.ROLE_ENVIRONMENT_USER);
    } else {
      namespaces = SecurityUtil.filter(authorizer, securityContext, Namespace.NAMESPACE, namespaces, READ);
    }
    return buildNamespacesGetResponse(namespaces, detail);
  }

  throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 16
Source File: UsernameForm.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
protected Response challenge(AuthenticationFlowContext context, MultivaluedMap<String, String> formData) {
    LoginFormsProvider forms = context.form();

    if (!formData.isEmpty()) forms.setFormData(formData);

    return forms.createLoginUsername();
}
 
Example 17
Source File: TagCatalogResource.java    From streamline with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * Lists all the tags in the system or the ones matching specific query params. For example to
 * list all the tags in the system,
 * </p>
 * <b>GET /api/v1/catalog/tags</b>
 * <p>
 * <pre>
 * {
 *   "entities": [
 *     {
 *       "id": 3,
 *       "name": "thermostat",
 *       "description": "thermostat device",
 *       "timestamp": 1481673224536,
 *       "tagIds": [
 *         2
 *       ]
 *     },
 *     {
 *       "id": 2,
 *       "name": "device",
 *       "description": "device tag",
 *       "timestamp": 1481673156548,
 *       "tagIds": []
 *     }
 *     ,
 *     ...
 *   ]
 * }
 * </pre>
 * <p>
 * <p>
 * The tags can also be listed based on specific query params. For example to list
 * tag(s) with the name "device",
 * </p>
 * <b>GET /api/v1/catalog/tags?name=device</b>
 * <pre>
 * {
 *   "entities": [
 *     {
 *       "id": 2,
 *       "name": "device",
 *       "description": "device tag",
 *       "timestamp": 1481673156548,
 *       "tagIds": []
 *     }
 *   ]
 * }
 * </pre>
 *
 * @param uriInfo the URI info which contains the query params
 * @return the response
 */
@GET
@Path("/tags")
@Timed
public Response listTags(@Context UriInfo uriInfo) {
    List<QueryParam> queryParams = new ArrayList<>();
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    Collection<Tag> tags;
    if (params.isEmpty()) {
        tags = tagService.listTags();
    } else {
        queryParams = WSUtils.buildQueryParameters(params);
        tags = tagService.listTags(queryParams);
    }
    if (tags != null)
        return WSUtils.respondEntities(makeTagDto(tags), OK);

    throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 18
Source File: TagCatalogResource.java    From registry with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * Lists all the tags in the system or the ones matching specific query params. For example to
 * list all the tags in the system,
 * </p>
 * <b>GET /api/v1/catalog/tags</b>
 * <p>
 * <pre>
 * {
 *   "entities": [
 *     {
 *       "id": 3,
 *       "name": "thermostat",
 *       "description": "thermostat device",
 *       "timestamp": 1481673224536,
 *       "tagIds": [
 *         2
 *       ]
 *     },
 *     {
 *       "id": 2,
 *       "name": "device",
 *       "description": "device tag",
 *       "timestamp": 1481673156548,
 *       "tagIds": []
 *     }
 *     ,
 *     ...
 *   ]
 * }
 * </pre>
 * <p>
 * <p>
 * The tags can also be listed based on specific query params. For example to list
 * tag(s) with the name "device",
 * </p>
 * <b>GET /api/v1/catalog/tags?name=device</b>
 * <pre>
 * {
 *   "entities": [
 *     {
 *       "id": 2,
 *       "name": "device",
 *       "description": "device tag",
 *       "timestamp": 1481673156548,
 *       "tagIds": []
 *     }
 *   ]
 * }
 * </pre>
 *
 * @param uriInfo the URI info which contains the query params
 * @return the response
 */
@GET
@Path("/tags")
@Timed
@UnitOfWork
public Response listTags(@Context UriInfo uriInfo) {
    List<QueryParam> queryParams = new ArrayList<>();
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    Collection<Tag> tags;
    if (params.isEmpty()) {
        tags = tagService.listTags();
    } else {
        queryParams = WSUtils.buildQueryParameters(params);
        tags = tagService.listTags(queryParams);
    }
    if (tags != null)
        return WSUtils.respondEntities(makeTagDto(tags), OK);

    throw EntityNotFoundException.byFilter(queryParams.toString());
}
 
Example 19
Source File: TrasformazioniUtils.java    From govpay with GNU General Public License v3.0 4 votes vote down vote up
private static void fillDynamicMap(Logger log, Map<String, Object> dynamicMap, IContext context, MultivaluedMap<String, String> queryParameters,
		MultivaluedMap<String, String> pathParameters, Map<String, String> headers, String json) {
	if(dynamicMap.containsKey(Costanti.MAP_DATE_OBJECT)==false) {
		dynamicMap.put(Costanti.MAP_DATE_OBJECT, DateManager.getDate());
	}

	if(context !=null) {
		if(dynamicMap.containsKey(Costanti.MAP_CTX_OBJECT)==false) {
			dynamicMap.put(Costanti.MAP_CTX_OBJECT, context);
		}
		if(dynamicMap.containsKey(Costanti.MAP_TRANSACTION_ID_OBJECT)==false) {
			String idTransazione = context.getTransactionId();
			dynamicMap.put(Costanti.MAP_TRANSACTION_ID_OBJECT, idTransazione);
		}

		GpContext ctx = (GpContext) ((org.openspcoop2.utils.service.context.Context)context).getApplicationContext();
		if(ctx !=null && ctx.getEventoCtx()!=null && ctx.getEventoCtx().getUrl() != null) {
			URLRegExpExtractor urle = new URLRegExpExtractor(ctx.getEventoCtx().getUrl(), log);
			dynamicMap.put(Costanti.MAP_ELEMENT_URL_REGEXP, urle);
			dynamicMap.put(Costanti.MAP_ELEMENT_URL_REGEXP.toLowerCase(), urle);
		}
	}

	if(dynamicMap.containsKey(Costanti.MAP_HEADER)==false && headers !=null) {
		dynamicMap.put(Costanti.MAP_HEADER, headers);
	}

	if(dynamicMap.containsKey(Costanti.MAP_QUERY_PARAMETER)==false && queryParameters!=null && !queryParameters.isEmpty()) {
		dynamicMap.put(Costanti.MAP_QUERY_PARAMETER, convertMultiToRegularMap(queryParameters));
	}

	if(dynamicMap.containsKey(Costanti.MAP_PATH_PARAMETER)==false && pathParameters!=null && !pathParameters.isEmpty()) {
		dynamicMap.put(Costanti.MAP_PATH_PARAMETER, convertMultiToRegularMap(pathParameters));
	}

	if(json !=null) {
		PatternExtractor pe = new PatternExtractor(json, log);
		dynamicMap.put(Costanti.MAP_ELEMENT_JSON_PATH, pe);
		dynamicMap.put(Costanti.MAP_ELEMENT_JSON_PATH.toLowerCase(), pe);
	}
}
 
Example 20
Source File: UDFCatalogResource.java    From streamline with Apache License 2.0 3 votes vote down vote up
/**
 * List ALL UDFs or the ones matching specific query params.
 * <p>
 * GET api/v1/catalog/udfs
 * </p>
 * <pre>
 * {
 *   "responseCode": 1000,
 *   "responseMessage": "Success",
 *   "entities": [
 *     {
 *       "id": 34,
 *       "name": "STDDEV",
 *       "description": "Standard deviation",
 *       "type": "AGGREGATE",
 *       "className": "com.hortonworks.streamline.streams.rule.udaf.Stddev"
 *     },
 *     { "id": 46,
 *        "name": "LOWER",
 *        "description": "Lowercase",
 *        "type": "FUNCTION",
 *        "className": "builtin"
 *     }
 *    ]
 * }
 * </pre>
 */
@GET
@Path("/udfs")
@Timed
public Response listUDFs(@Context UriInfo uriInfo,
                         @Context SecurityContext securityContext) {
    List<QueryParam> queryParams = new ArrayList<>();
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    Collection<UDF> udfs;
    if (params.isEmpty()) {
        udfs = catalogService.listUDFs();
    } else {
        queryParams = WSUtils.buildQueryParameters(params);
        udfs = catalogService.listUDFs(queryParams);
    }
    if (udfs != null) {
        boolean udfUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_UDF_USER);
        if (udfUser) {
            LOG.debug("Returning all UDFs since user has role: {}", Roles.ROLE_UDF_USER);
        } else {
            udfs = SecurityUtil.filter(authorizer, securityContext, UDF.NAMESPACE, udfs, READ);
        }
        return WSUtils.respondEntities(udfs, OK);
    }

    throw EntityNotFoundException.byFilter(queryParams.toString());
}