use of org.finos.symphony.toolkit.workflow.annotations.Work in project spring-bot by finos.
the class WorkResponseConverter method canConvert.
@Override
public boolean canConvert(Object in) {
if (in == null) {
return false;
}
Class<?> c = in.getClass();
Work work = c.getAnnotation(Work.class);
if (work != null) {
return true;
}
return false;
}
use of org.finos.symphony.toolkit.workflow.annotations.Work in project spring-bot by finos.
the class HeaderTagResponseHandler method accept.
/**
* This ensures that the JSON data being sent will contain a HeaderDetails
* object, which contains a list of {@link HashTag}s that need to be present in
* the message for indexing purposes.
*/
@Override
public void accept(Response t) {
if (t instanceof WorkResponse) {
WorkResponse workResponse = (WorkResponse) t;
HeaderDetails hd = (HeaderDetails) workResponse.getData().get(HeaderDetails.KEY);
if (hd == null) {
hd = new HeaderDetails();
workResponse.getData().put(HeaderDetails.KEY, hd);
}
// make sure all tags are unique, maintain order from original.
Set<HashTag> tags = new LinkedHashSet<>();
tags.addAll(hd.getTags());
// check through other stuff in the json response
for (Object o2 : workResponse.getData().values()) {
Work w = o2 != null ? o2.getClass().getAnnotation(Work.class) : null;
if ((w != null) && (w.index())) {
tags.addAll(TagSupport.classHashTags(o2));
}
}
hd.setTags(new ArrayList<HashTag>(tags));
}
}
use of org.finos.symphony.toolkit.workflow.annotations.Work in project spring-bot by finos.
the class SymphonyWorkflowConfig method scanForWorkClasses.
protected List<VersionSpace> scanForWorkClasses() {
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(Work.class));
Set<BeanDefinition> toAdd = scanner.findCandidateComponents(getPackageName(ChatWorkflowConfig.class));
for (String ent : ac.getBeanNamesForAnnotation(SpringBootApplication.class)) {
String packageName = getPackageName(ac.getBean(ent).getClass());
Set<BeanDefinition> user = scanner.findCandidateComponents(packageName);
toAdd.addAll(user);
}
List<VersionSpace> versionSpaces = toAdd.stream().map(bd -> bd.getBeanClassName()).map(s -> {
try {
return Class.forName(s);
} catch (ClassNotFoundException e) {
LOG.error("Couldn't instantiate: " + s, e);
return null;
}
}).filter(x -> x != null).flatMap(c -> {
Work w = c.getAnnotation(Work.class);
String[] jsonTypeName = w.jsonTypeName();
return IntStream.range(0, jsonTypeName.length).mapToObj(i -> {
String t = jsonTypeName[i];
if (i == 0) {
t = StringUtils.hasText(t) ? t : EntityJson.getSymphonyTypeName(c);
String writeVersion = w.writeVersion();
String[] readVersions = w.readVersions();
return new VersionSpace(t, c, writeVersion, readVersions);
} else {
String[] readVersions = w.readVersions();
return new VersionSpace(t, c, null, readVersions);
}
});
}).collect(Collectors.toList());
return versionSpaces;
}
Aggregations