use of io.narayana.sra.annotation.Prepare 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;
}
Aggregations