use of io.bssw.psip.backend.data.Item 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.Item in project psip-automation by bssw-psip.
the class Assessment method createItemLayout.
private void createItemLayout(Item item) {
mainLayout.removeAll();
ScoreItem scoreItem = new ScoreItem(item);
String path = item.getCategory().getActivity().getPath() + "/" + item.getCategory().getPath() + "/" + item.getPath();
Item prevItem = activityService.getPrevItem(path);
Button button1 = UIUtils.createLargeButton(VaadinIcon.CHEVRON_CIRCLE_LEFT);
// FIXME: Don't hard code background
button1.getElement().getStyle().set("background", "#F3F5F7").set("font-size", "30px");
button1.getElement().addEventListener("click", e -> {
MainLayout.navigate(Assessment.class, prevItem.getCategory().getPath() + "/" + prevItem.getPath());
});
if (prevItem == null) {
button1.getElement().setEnabled(false);
}
Item nextItem = activityService.getNextItem(path);
Button button2 = UIUtils.createLargeButton(VaadinIcon.CHEVRON_CIRCLE_RIGHT);
// FIXME: Don't hard code background
button2.getElement().getStyle().set("background", "#F3F5F7").set("font-size", "30px");
button2.getElement().addEventListener("click", e -> {
MainLayout.navigate(Assessment.class, nextItem.getCategory().getPath() + "/" + nextItem.getPath());
});
if (nextItem == null) {
button2.getElement().setEnabled(false);
}
HorizontalLayout hz = new HorizontalLayout(button1, button2);
hz.setJustifyContentMode(JustifyContentMode.CENTER);
hz.setWidthFull();
Anchor anchor = new Anchor();
anchor.setText("Show me my assessment");
anchor.getElement().addEventListener("click", e -> MainLayout.navigate(Assessment.class, null));
HorizontalLayout hz2 = new HorizontalLayout(anchor);
hz2.setJustifyContentMode(JustifyContentMode.CENTER);
hz2.setWidthFull();
VerticalLayout footer = new VerticalLayout(hz, hz2);
footer.setMargin(false);
mainLayout.addAndExpand(scoreItem, footer);
}
use of io.bssw.psip.backend.data.Item 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.Item 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.Item 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();
}
}
Aggregations