Search in sources :

Example 1 with OnePhaseCommit

use of io.narayana.sra.annotation.OnePhaseCommit in project narayana by jbosstm.

the class SRAClient method getTerminationUris.

public Map<String, String> getTerminationUris(Class<?> compensatorClass, URI baseUri, boolean validate) {
    Map<String, String> paths = new HashMap<>();
    Annotation resourcePathAnnotation = compensatorClass.getAnnotation(Path.class);
    String resourcePath = resourcePathAnnotation == null ? "/" : ((Path) resourcePathAnnotation).value();
    String uriPrefix = String.format("%s:%s%s", baseUri.getScheme(), baseUri.getSchemeSpecificPart(), resourcePath.substring(1));
    final int[] validCnt = { 0 };
    Arrays.stream(compensatorClass.getMethods()).forEach(method -> {
        Annotation pathAnnotation = method.getAnnotation(Path.class);
        if (pathAnnotation != null) {
            if (checkMethod(paths, STATUS, (Path) pathAnnotation, method.getAnnotation(Status.class), uriPrefix)) {
                validCnt[0] += 1;
            }
            if (checkMethod(paths, PREPARE, (Path) pathAnnotation, method.getAnnotation(Prepare.class), uriPrefix)) {
                validCnt[0] += 1;
            }
            if (checkMethod(paths, COMMIT, (Path) pathAnnotation, method.getAnnotation(Commit.class), uriPrefix)) {
                validCnt[0] += 1;
            }
            if (checkMethod(paths, ROLLBACK, (Path) pathAnnotation, method.getAnnotation(Rollback.class), uriPrefix)) {
                validCnt[0] += 1;
            }
            checkMethod(paths, ONEPHASECOMMIT, (Path) pathAnnotation, method.getAnnotation(OnePhaseCommit.class), uriPrefix);
        }
    });
    if (validate && validCnt[0] < 4) {
        if (!paths.containsKey(COMMIT) && !paths.containsKey(ONEPHASECOMMIT))
            throw new GenericSRAException(null, Response.Status.BAD_REQUEST.getStatusCode(), String.format(MISSING_ANNOTATION_FORMAT, compensatorClass.getName()), null);
    }
    StringBuilder linkHeaderValue = new StringBuilder();
    paths.forEach((k, v) -> makeLink(linkHeaderValue, null, k, v));
    paths.put("Link", linkHeaderValue.toString());
    return paths;
}
Also used : Status(io.narayana.sra.annotation.Status) Commit(io.narayana.sra.annotation.Commit) OnePhaseCommit(io.narayana.sra.annotation.OnePhaseCommit) HashMap(java.util.HashMap) Prepare(io.narayana.sra.annotation.Prepare) Rollback(io.narayana.sra.annotation.Rollback) OnePhaseCommit(io.narayana.sra.annotation.OnePhaseCommit) Annotation(java.lang.annotation.Annotation)

Aggregations

Commit (io.narayana.sra.annotation.Commit)1 OnePhaseCommit (io.narayana.sra.annotation.OnePhaseCommit)1 Prepare (io.narayana.sra.annotation.Prepare)1 Rollback (io.narayana.sra.annotation.Rollback)1 Status (io.narayana.sra.annotation.Status)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1