use of io.bssw.psip.backend.data.Category in project psip-automation by bssw-psip.
the class Assessment method generateSaveUrl.
/**
* Generate a url that can be used to resume assessment
* @param activity
* @return url
*/
private String generateSaveUrl(Activity activity) {
StringBuilder query = new StringBuilder();
Iterator<Category> categoryIter = activity.getCategories().iterator();
while (categoryIter.hasNext()) {
Category category = categoryIter.next();
query.append(category.getPath() + "=");
StringBuilder nested = new StringBuilder();
Iterator<Item> itemIter = category.getItems().iterator();
while (itemIter.hasNext()) {
Item item = itemIter.next();
nested.append(item.getPath() + ":" + item.getScore().orElse(0));
if (itemIter.hasNext()) {
nested.append("+");
}
}
query.append(nested.toString());
if (categoryIter.hasNext()) {
query.append("&");
}
}
return getLocation() + RouteConfiguration.forSessionScope().getUrl(Assessment.class, "?" + query.toString());
}
use of io.bssw.psip.backend.data.Category in project psip-automation by bssw-psip.
the class Assessment method setParameter.
@Override
public void setParameter(BeforeEvent event, @WildcardParameter String parameter) {
String desc = "";
if (parameter.isEmpty()) {
Activity activity = activityService.getActivity("Assessment");
desc = activity.getDescription();
// Get query parameters and restore state if there are any
Location location = event.getLocation();
QueryParameters queryParameters = location.getQueryParameters();
Map<String, List<String>> parametersMap = queryParameters.getParameters();
if (!parametersMap.isEmpty()) {
restoreSaveUrl(activity, parametersMap);
}
createActivityLayout(activity);
} else if (parameter.contains("/")) {
// Item
Item item = activityService.getItem("assessment/" + parameter);
if (item != null) {
desc = item.getDescription();
createItemLayout(item);
} else {
System.out.println("invalid parameter=" + parameter);
}
} else {
// Category
Category category = activityService.getCategory("assessment/" + parameter);
desc = category.getDescription();
createCategoryLayout(category);
}
description.getElement().setText(desc);
}
use of io.bssw.psip.backend.data.Category in project psip-automation by bssw-psip.
the class Assessment method createActivitySummaryAsProgress.
@SuppressWarnings("unused")
private Component createActivitySummaryAsProgress(Activity activity) {
FormLayout form = new FormLayout();
for (Category category : activity.getCategories()) {
int score = 0;
for (Item item : category.getItems()) {
if (item.getScore().isPresent()) {
score += item.getScore().get();
}
}
ProgressBar bar = new ProgressBar(0, category.getItems().size() > 0 ? 100 * category.getItems().size() : 1);
bar.getElement().getStyle().set("height", "10px");
bar.setValue(score);
if (category.getItems().isEmpty()) {
bar.getElement().setEnabled(false);
}
FormItem formItem = form.addFormItem(bar, category.getName());
// Set width of label otherwise it will wrap
formItem.getElement().getStyle().set("--vaadin-form-item-label-width", "15em");
// FormLayout defaults to 2 columns so span both
form.setColspan(formItem, 2);
}
return form;
}
use of io.bssw.psip.backend.data.Category in project psip-automation by bssw-psip.
the class GenData method run.
public void run(String input, Optional<String> output) throws IOException {
Yaml yaml = new Yaml(new Constructor(Content.class));
InputStream inputStream = FileUtils.openInputStream(new File(input));
Content content = yaml.load(inputStream);
if (output.isPresent()) {
BufferedWriter bw = Files.newBufferedWriter(Paths.get(output.get()));
PrintWriter writer = new PrintWriter(bw);
int activity_id = 1;
for (Activity activity : content.getActivities()) {
writer.println("insert into activity (id, name, icon, path, description) values (" + activity_id++ + ", '" + activity.getName() + "', '" + activity.getIcon() + "', '" + activity.getPath() + "', '" + activity.getDescription() + "');");
}
writer.println("commit;");
activity_id = 1;
int score_id = 1;
for (Activity activity : content.getActivities()) {
for (Score score : activity.getScores()) {
writer.println("insert into score (id, name, boost, value, color, activity_id) values (" + score_id++ + ", '" + score.getName() + "', '" + score.getBoost() + "', " + score.getValue() + ", '" + score.getColor() + "', " + activity_id + ");");
}
activity_id++;
}
writer.println("commit;");
activity_id = 1;
int category_id = 1;
for (Activity activity : content.getActivities()) {
for (Category category : activity.getCategories()) {
writer.println("insert into category (id, name, activity_id, icon, path, description) values (" + category_id++ + ", '" + category.getName() + "', " + activity_id + ", '', '" + category.getPath() + "', '" + category.getDescription() + "');");
}
activity_id++;
}
writer.println("commit;");
category_id = 1;
int item_id = 1;
for (Activity activity : content.getActivities()) {
for (Category category : activity.getCategories()) {
for (Item item : category.getItems()) {
writer.println("insert into item (id, name, category_id, icon, path, description) values (" + item_id++ + ", '" + item.getName() + "', " + category_id + ", '', '" + item.getPath() + "', '" + item.getDescription() + "');");
}
category_id++;
}
}
writer.println("commit;");
item_id = 1;
for (Activity activity : content.getActivities()) {
for (Category category : activity.getCategories()) {
for (Item item : category.getItems()) {
for (String question : item.getQuestions()) {
writer.println("insert into item_questions (item_id, questions) values (" + item_id + ", '" + question + "');");
}
item_id++;
}
}
}
writer.println("commit;");
writer.close();
}
}
use of io.bssw.psip.backend.data.Category in project psip-automation by bssw-psip.
the class MainLayout method initNaviItems.
/**
* Initialize the navigation items.
*/
private <C extends Component & HasUrlParameter<String>> void initNaviItems() {
NaviMenu menu = naviDrawer.getMenu();
menu.addNaviItem(VaadinIcon.HOME, "Home", Home.class);
for (Activity activity : activityService.getActivities()) {
Optional<Class<? extends Component>> optRoute = RouteConfiguration.forSessionScope().getRoute(activity.getPath(), Collections.singletonList(""));
if (optRoute.isPresent()) {
activityService.setActivity(activity.getName(), activity);
Class<? extends Component> route = optRoute.get();
NaviItem actNav = menu.addNaviItem(VaadinIcon.valueOf(activity.getIcon()), activity.getName(), optRoute.get());
naviItems.put(activity.getPath(), actNav);
ListIterator<Category> categoryIter = activity.getCategories().listIterator();
Item prev = null;
Item next = null;
while (categoryIter.hasNext()) {
Category category = categoryIter.next();
if (HasUrlParameter.class.isAssignableFrom(route)) {
@SuppressWarnings("unchecked") NaviItem catNav = menu.addNaviItem(actNav, category.getName(), (Class<? extends C>) route, category.getPath());
String catPath = activity.getPath() + "/" + category.getPath();
activityService.setCategory(catPath, category);
naviItems.put(catPath, catNav);
ListIterator<Item> itemIter = category.getItems().listIterator();
while (itemIter.hasNext()) {
Item item = itemIter.next();
next = findNextItem(itemIter, categoryIter, category, activity);
String itemNavPath = category.getPath() + "/" + item.getPath();
NaviItem naviItem = menu.addNaviItem(catNav, item.getName(), (Class<? extends C>) route, itemNavPath);
String itemPath = activity.getPath() + "/" + itemNavPath;
activityService.setItem(itemPath, item);
activityService.setPrevItem(itemPath, prev);
activityService.setNextItem(itemPath, next);
naviItems.put(itemPath, naviItem);
String p = prev != null ? prev.getName() : "";
String n = next != null ? next.getName() : "";
prev = item;
}
catNav.setExpanded(false);
}
}
actNav.setExpanded(false);
}
}
}
Aggregations