Java Code Examples for org.springframework.web.util.UriComponentsBuilder#fromPath()

The following examples show how to use org.springframework.web.util.UriComponentsBuilder#fromPath() . These examples are extracted from open source projects. 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 Project: mojito   File: AssetClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Imports a localized version of an asset.
 *
 * The target strings are checked against the source strings and if they are
 * equals the status of the imported translation is defined by
 * statusForEqualTarget. When SKIIED is specified the import is actually
 * skipped.
 *
 * For not fully translated locales, targets are imported only if they are
 * different from target of the parent locale.
 *
 * @param assetId {@link Asset#id}
 * @param localeId {@link Locale#id}
 * @param content the asset content to be localized
 * @param statusForEqualTarget the status of the text unit variant when
 * the target is the same as the parent
 * @param filterConfigIdOverride
 * @param filterOptions
 * @return
 */
public ImportLocalizedAssetBody importLocalizedAssetForContent(
        Long assetId,
        Long localeId,
        String content,
        ImportLocalizedAssetBody.StatusForEqualTarget statusForEqualTarget,
        FilterConfigIdOverride filterConfigIdOverride,
        List<String> filterOptions) {
    logger.debug("Import localized asset with asset id = {}, locale id = {}", assetId, localeId);

    UriComponentsBuilder uriBuilder = UriComponentsBuilder
            .fromPath(getBasePathForResource(assetId, "localized", localeId, "import"));

    ImportLocalizedAssetBody importLocalizedAssetBody = new ImportLocalizedAssetBody();
    importLocalizedAssetBody.setContent(content);
    importLocalizedAssetBody.setStatusForEqualTarget(statusForEqualTarget);
    importLocalizedAssetBody.setFilterConfigIdOverride(filterConfigIdOverride);
    importLocalizedAssetBody.setFilterOptions(filterOptions);

    return authenticatedRestTemplate.postForObject(uriBuilder.toUriString(),
            importLocalizedAssetBody,
            ImportLocalizedAssetBody.class);
}
 
Example 2
Source Project: nakadi   File: SubscriptionsUriHelper.java    License: MIT License 6 votes vote down vote up
public static String createSubscriptionListUri(final Optional<String> owningApplication,
                                               final Set<String> eventTypes, final int offset, final int limit,
                                               final boolean showStatus) {

    final UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromPath("/subscriptions");
    if (!eventTypes.isEmpty()) {
        urlBuilder.queryParam("event_type", eventTypes.toArray());
    }
    owningApplication.ifPresent(owningApp -> urlBuilder.queryParam("owning_application", owningApp));
    if (showStatus) {
        urlBuilder.queryParam("show_status", "true");
    }
    return urlBuilder
            .queryParam("offset", offset)
            .queryParam("limit", limit)
            .build()
            .toString();
}
 
Example 3
Source Project: sinavi-jfw   File: PostBackManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 現在のリクエストに対応するコントローラのハンドラーメソッドに設定されている例外発生時のアクション定義({@link PostBack#Action}注釈)
 * から、指定した例外に対応するアクションが定義を検索しポスト・バックするURLを生成します。
 * URL生成時に指定した例外タイプに該当する{@link PostBack#Action}注釈の{@code params}属性を解析し
 * クエリ・パラメータを付加します。
 * @param t 例外タイプ
 * @param o モデルオブジェクト
 * @param encode エンコードの有無
 * @return ポスト・バック先URL
 */
public static String buildUri(Throwable t, Object o, boolean encode) {
    PostBack.Action action = getPostBackAction(t);
    String path = action.value();
    String[] pathParameters = action.pathParams();
    if (pathParameters.length > 1) {
        path = Strings.substitute(path, values(o, pathParameters));
    }
    UriComponentsBuilder builder = UriComponentsBuilder.fromPath(path);
    String[] parameters = action.params();
    if (parameters.length > 1) {
        Map<String, String> valueMaps = values(o, parameters);
        Set<String> sets = valueMaps.keySet();
        for (String key : sets) {
            builder.queryParam(key, valueMaps.get(key));
        }
    }
    if (encode) {
        return builder.build().encode().toString();
    } else {
        return builder.build().toString();
    }
}
 
Example 4
Source Project: mojito   File: AssetClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns list of {@link Asset#id} for a given {@link Repository}
 *
 * @param repositoryId
 * @param deleted optional
 * @param virtual optional
 * @param branch optional
 * @return
 */
public List<Long> getAssetIds(Long repositoryId, Boolean deleted, Boolean virtual, Long branchId) {
    Assert.notNull(repositoryId);

    UriComponentsBuilder uriBuilder = UriComponentsBuilder
            .fromPath(getBasePathForEntity() + "/ids");

    Map<String, String> params = new HashMap<>();
    params.put("repositoryId", repositoryId.toString());

    if (deleted != null) {
        params.put("deleted", deleted.toString());
    }

    if (virtual != null) {
        params.put("virtual", virtual.toString());
    }

    if (branchId != null) {
        params.put("branch", branchId.toString());
    }

    return authenticatedRestTemplate.getForObjectAsListWithQueryStringParams(uriBuilder.toUriString(), Long[].class, params);
}
 
Example 5
Source Project: mojito   File: AssetClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets a pseudo localized version of provided content, the content is
 * related to a given Asset.
 *
 * The content can be a new version of the asset stored in the TMS. This is
 * used to pseudo localize files during development with usually minor
 * changes done to the persisted asset.
 *
 * @param assetId {@link Asset#id}
 * @param content the asset content to be pseudolocalized
 * @param filterConfigIdOverride Optional, can be null. Allows to specify a
 * specific Okapi filter to use to process the asset
 * @param filterOptions
 * @return the pseudoloocalized asset content
 */
public LocalizedAssetBody getPseudoLocalizedAssetForContent(Long assetId, String content, FilterConfigIdOverride filterConfigIdOverride, List<String> filterOptions) {

    UriComponentsBuilder uriBuilder = UriComponentsBuilder
            .fromPath(getBasePathForResource(assetId, "pseudo"));

    LocalizedAssetBody localizedAssetBody = new LocalizedAssetBody();
    localizedAssetBody.setContent(content);
    localizedAssetBody.setOutputBcp47tag(OUTPUT_BCP47_TAG);
    localizedAssetBody.setFilterConfigIdOverride(filterConfigIdOverride);
    localizedAssetBody.setFilterOptions(filterOptions);

    return authenticatedRestTemplate.postForObject(uriBuilder.toUriString(),
            localizedAssetBody,
            LocalizedAssetBody.class);
}
 
Example 6
Source Project: mojito   File: AssetClient.java    License: Apache License 2.0 5 votes vote down vote up
public PollableTask getLocalizedAssetForContentAsync(
        Long assetId,
        Long localeId,
        String content,
        String outputBcp47tag,
        FilterConfigIdOverride filterConfigIdOverride,
        List<String> filterOptions,
        LocalizedAssetBody.Status status,
        LocalizedAssetBody.InheritanceMode inheritanceMode) {
    logger.debug("Getting localized asset with asset id = {}, locale id = {}, outputBcp47tag: {}", assetId, localeId, outputBcp47tag);

    UriComponentsBuilder uriBuilder = UriComponentsBuilder
            .fromPath(getBasePathForResource(assetId, "localized"));

    LocalizedAssetBody localizedAssetBody = new LocalizedAssetBody();
    localizedAssetBody.setAssetId(assetId);
    localizedAssetBody.setLocaleId(localeId);
    localizedAssetBody.setContent(content);
    localizedAssetBody.setOutputBcp47tag(outputBcp47tag);
    localizedAssetBody.setFilterConfigIdOverride(filterConfigIdOverride);
    localizedAssetBody.setFilterOptions(filterOptions);
    localizedAssetBody.setInheritanceMode(inheritanceMode);
    localizedAssetBody.setStatus(status);

    PollableTask pollableTask = authenticatedRestTemplate.postForObject(uriBuilder.toUriString(),
            localizedAssetBody,
            PollableTask.class);


    return pollableTask;
}
 
Example 7
Source Project: sinavi-jfw   File: PostBackManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * クエリ・パラメータ付きのURLを生成します。
 * @param path パス
 * @param parameters クエリ・パラメータが格納された{@link Map}インスタンス
 * @param encode エンコードの有無
 * @return クエリ・パラメータ付きのURL
 */
public static String buildUri(String path, Map<String, String> parameters, boolean encode) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromPath(path);
    if (!parameters.isEmpty()) {
        Set<String> sets = parameters.keySet();
        for (String key : sets) {
            builder.queryParam(key, parameters.get(key));
        }
    }
    if (encode) {
        return builder.build().encode().toString();
    } else {
        return builder.build().toString();
    }
}
 
Example 8
private String buildUrl(String address, String path, Map<String, Map<String, String>> params) {
  UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(path);
  params.getOrDefault(SagaRequest.PARAM_QUERY, emptyMap())
      .forEach(uriComponentsBuilder::queryParam);

  return protocol + address + uriComponentsBuilder.build().toString();
}
 
Example 9
private String buildGuestPath(String currentLanguage, List<String> languages) {
	UriComponentsBuilder builder = UriComponentsBuilder.fromPath("");
	if (languages.size() > 1) {
		builder.path("/{language}");
	}
	return builder.buildAndExpand(currentLanguage).toUriString();
}
 
Example 10
Source Project: wallride   File: Users.java    License: Apache License 2.0 4 votes vote down vote up
public String path(User user, boolean encode) {
	UriComponentsBuilder builder = UriComponentsBuilder.fromPath("");
	return path(builder, user, encode);
}
 
Example 11
Source Project: wallride   File: PostUtils.java    License: Apache License 2.0 4 votes vote down vote up
public String path(Article article) {
	UriComponentsBuilder builder = UriComponentsBuilder.fromPath("");
	return path(builder, article, true);
}
 
Example 12
@Override
public String getOperationPath(String operationPath) {
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
    return Paths.removeAdjacentForwardSlashes(
            uriComponentsBuilder.path(operationPath.replaceFirst("^" + basePath, "")).build().toString());
}
 
Example 13
@Override
public String getOperationPath(String operationPath) {
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
    return Paths.removeAdjacentForwardSlashes(
            uriComponentsBuilder.path(operationPath.replaceFirst("^" + basePath, "")).build().toString());
}
 
Example 14
Source Project: wallride   File: PostUtils.java    License: Apache License 2.0 4 votes vote down vote up
public String path(Page page) {
	UriComponentsBuilder builder = UriComponentsBuilder.fromPath("");
	return path(builder, page, true);
}
 
Example 15
@Override
public String getOperationPath(String operationPath) {
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
    return Paths.removeAdjacentForwardSlashes(
            uriComponentsBuilder.path(operationPath.replaceFirst("^" + basePath, "")).build().toString());
}
 
Example 16
@Override
public String getOperationPath(String operationPath) {
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
    return Paths.removeAdjacentForwardSlashes(
            uriComponentsBuilder.path(operationPath.replaceFirst("^" + basePath, "")).build().toString());
}
 
Example 17
Source Project: syndesis   File: OpenAPIConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getOperationPath(String operationPath) {
    UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
    return Paths.removeAdjacentForwardSlashes(
            uriComponentsBuilder.path(operationPath.replaceFirst("^" + basePath, "")).build().toString());
}
 
Example 18
private static UriComponentsBuilder initBaseUrl() {
	UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentServletMapping();
	return UriComponentsBuilder.fromPath(builder.build().getPath());
}
 
Example 19
private String buildAdminPath(String currentLanguage) {
//		String contextPath = request.getContextPath();
		UriComponentsBuilder builder = UriComponentsBuilder.fromPath(WallRideServletConfiguration.ADMIN_SERVLET_PATH);
		builder.path("/{language}");
		return builder.buildAndExpand(currentLanguage).toUriString();
	}
 
Example 20
Source Project: mojito   File: BaseClient.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Construct a base path for a resource and subresources matching the {@param resourceId}
 * <p/>
 * Example 1:
 * <pre class="code">
 * getBasePathForResource(repoId, "repositoryLocales");
 * </pre>
 * will print: <blockquote>{@code /api/entityName/repoId/repositoryLocales/}</blockquote>
 * Example 2:
 * <pre class="code">
 * getBasePathForResource(repoId, "repositoryLocales", 1);
 * </pre>
 * will print: <blockquote>{@code /api/entityName/repoId/repositoryLocales/1}</blockquote>
 *
 * @param resourceId The resourceId of the resource
 * @param pathSegments An undefined number of path segments to concatenate to the URI
 * @return
 */
protected String getBasePathForResource(Long resourceId, Object... pathSegments) {
    UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath(getBasePathForResource(resourceId));

    if (!ObjectUtils.isEmpty(pathSegments)) {
        for (Object pathSegment : pathSegments) {
            uriBuilder.pathSegment(pathSegment.toString());
        }
    }

    return uriBuilder.toUriString();
}