in tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/DeploymentCommandSupport.java [105:203]
public Object execute() throws Exception {
List<Bundle> bundlesToUpdate;
if ("*".equals(definitionType)) {
definitionType = ALL_OPTION_LABEL;
}
if ("*".equals(fileName)) {
fileName = ALL_OPTION_LABEL;
}
if (bundleIdentifier == null) {
List<Bundle> bundles = new ArrayList<>();
for (Bundle bundle : bundleContext.getBundles()) {
if (bundle.findEntries("META-INF/cxs/", "*.json", true) != null) {
bundles.add(bundle);
}
}
bundles = bundles.stream()
.filter(b -> definitionTypes.stream().anyMatch((t) -> b.findEntries(getDefinitionTypePath(t), "*.json", true) != null))
.collect(Collectors.toList());
List<String> bundleSymbolicNames = bundles.stream().map(Bundle::getSymbolicName).collect(Collectors.toList());
bundleSymbolicNames.add(ALL_OPTION_LABEL);
String bundleAnswer = askUserWithAuthorizedAnswer(session, "Which bundle ?" + getValuesWithNumber(bundleSymbolicNames) + "\n",
IntStream.range(1,bundleSymbolicNames.size()+1).mapToObj(Integer::toString).collect(Collectors.toList()));
String selectedBundle = bundleSymbolicNames.get(new Integer(bundleAnswer)-1);
if (selectedBundle.equals(ALL_OPTION_LABEL)) {
bundlesToUpdate = bundles;
} else {
bundlesToUpdate = Collections.singletonList(bundles.get(new Integer(bundleAnswer) - 1));
}
} else {
Bundle bundle = bundleContext.getBundle(bundleIdentifier);
if (bundle == null) {
System.out.println("Couldn't find a bundle with id: " + bundleIdentifier);
return null;
}
bundlesToUpdate = Collections.singletonList(bundle);
}
if (definitionType == null) {
List<String> possibleDefinitionNames = definitionTypes.stream().filter((t) -> bundlesToUpdate.stream().anyMatch(b->b.findEntries(getDefinitionTypePath(t), "*.json", true) != null)).collect(Collectors.toList());
possibleDefinitionNames.add(ALL_OPTION_LABEL);
if (possibleDefinitionNames.isEmpty()) {
System.out.println("Couldn't find definitions in bundle : " + bundlesToUpdate);
return null;
}
String definitionTypeAnswer = askUserWithAuthorizedAnswer(session, "Which kind of definition do you want to load?" + getValuesWithNumber(possibleDefinitionNames) + "\n",
IntStream.range(1,possibleDefinitionNames.size()+1).mapToObj(Integer::toString).collect(Collectors.toList()));
definitionType = possibleDefinitionNames.get(new Integer(definitionTypeAnswer)-1);
}
if (!definitionTypes.contains(definitionType) && !ALL_OPTION_LABEL.equals(definitionType)) {
System.out.println("Invalid type '" + definitionType + "' , allowed values : " +definitionTypes);
return null;
}
String definitionTypePath = getDefinitionTypePath(definitionType);
List<URL> definitionTypeURLs = bundlesToUpdate.stream().flatMap(b->b.findEntries(definitionTypePath, "*.json", true) != null ? Collections.list(b.findEntries(definitionTypePath, "*.json", true)).stream() : Stream.empty()).collect(Collectors.toList());
if (definitionTypeURLs.isEmpty()) {
System.out.println("Couldn't find definitions in bundle with id: " + bundleIdentifier + " and definition path: " + definitionTypePath);
return null;
}
if (fileName == null) {
List<String> definitionTypeFileNames = definitionTypeURLs.stream().map(u -> StringUtils.substringAfterLast(u.getFile(), "/")).sorted().collect(Collectors.toList());
definitionTypeFileNames.add(ALL_OPTION_LABEL);
String fileNameAnswer = askUserWithAuthorizedAnswer(session, "Which file do you want to load ?" + getValuesWithNumber(definitionTypeFileNames) + "\n",
IntStream.range(1,definitionTypeFileNames.size()+1).mapToObj(Integer::toString).collect(Collectors.toList()));
fileName = definitionTypeFileNames.get(new Integer(fileNameAnswer)-1);
}
if (ALL_OPTION_LABEL.equals(fileName)) {
for (URL url : definitionTypeURLs) {
processDefinition(definitionType, url);
}
} else {
if (!fileName.contains("/")) {
fileName = "/" + fileName;
}
if (!fileName.endsWith(".json")) {
fileName += ".json";
}
Optional<URL> optionalURL = definitionTypeURLs.stream().filter(u -> u.getFile().endsWith(fileName)).findFirst();
if (optionalURL.isPresent()) {
URL url = optionalURL.get();
processDefinition(definitionType, url);
} else {
System.out.println("Couldn't find file " + fileName);
return null;
}
}
return null;
}