From 549203b985312dc29b1926dabcc7b354c9f5221c Mon Sep 17 00:00:00 2001 From: Dmytro Titov Date: Tue, 1 Oct 2019 14:22:26 +0200 Subject: [PATCH] Show icon if the hub is crawled and validated --- pom.xml | 2 +- .../data/providers/AbstractDataProvider.java | 1 - .../ifi/trackfind/backend/pojo/TfVersion.java | 4 +-- .../services/impl/EPICOValidationService.java | 28 ++++++++++++++++--- .../trackfind/frontend/TrackFindHubsUI.java | 19 +++++++++++-- .../frontend/TrackFindVersionsUI.java | 2 +- src/main/resources/schema.sql | 18 ++++++------ 7 files changed, 53 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 63413191..d7ac70b1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ no.uio.ifi trackfind - 2.8.0 + 2.8.1 jar trackfind diff --git a/src/main/java/no/uio/ifi/trackfind/backend/data/providers/AbstractDataProvider.java b/src/main/java/no/uio/ifi/trackfind/backend/data/providers/AbstractDataProvider.java index b8b02a2f..662ff512 100644 --- a/src/main/java/no/uio/ifi/trackfind/backend/data/providers/AbstractDataProvider.java +++ b/src/main/java/no/uio/ifi/trackfind/backend/data/providers/AbstractDataProvider.java @@ -174,7 +174,6 @@ protected TfVersion createVersion(String hubName, Operation operation, boolean c newVersion.setUser((TfUser) authentication.getPrincipal()); } newVersion.setTime(new Date()); - newVersion.setValidated(false); newVersion.setHub(hub); if (Operation.CURATION.equals(operation) && currentVersionOptional.isPresent()) { newVersion.setBasedOn(currentVersionOptional.get()); diff --git a/src/main/java/no/uio/ifi/trackfind/backend/pojo/TfVersion.java b/src/main/java/no/uio/ifi/trackfind/backend/pojo/TfVersion.java index f7df99e7..3e2af39d 100644 --- a/src/main/java/no/uio/ifi/trackfind/backend/pojo/TfVersion.java +++ b/src/main/java/no/uio/ifi/trackfind/backend/pojo/TfVersion.java @@ -45,8 +45,8 @@ public class TfVersion implements Serializable { @Column(name = "time", nullable = false) private Date time; - @Column(name = "validated", nullable = false) - private Boolean validated; + @Column(name = "validation") + private Boolean validation; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "hub_id", referencedColumnName = "id") diff --git a/src/main/java/no/uio/ifi/trackfind/backend/services/impl/EPICOValidationService.java b/src/main/java/no/uio/ifi/trackfind/backend/services/impl/EPICOValidationService.java index ce02b992..f7941e67 100644 --- a/src/main/java/no/uio/ifi/trackfind/backend/services/impl/EPICOValidationService.java +++ b/src/main/java/no/uio/ifi/trackfind/backend/services/impl/EPICOValidationService.java @@ -3,6 +3,8 @@ import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; import no.uio.ifi.trackfind.backend.pojo.TfObjectType; +import no.uio.ifi.trackfind.backend.pojo.TfVersion; +import no.uio.ifi.trackfind.backend.repositories.VersionRepository; import no.uio.ifi.trackfind.backend.services.ValidationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; @@ -30,24 +32,37 @@ public class EPICOValidationService implements ValidationService { private JdbcTemplate jdbcTemplate; private MetamodelService metamodelService; + private VersionRepository versionRepository; private RestTemplate restTemplate; private Gson gson; /** * {@inheritDoc} */ + @SuppressWarnings("unchecked") @Override - public String validate(String repository, String hub) { + public String validate(String repository, String hubName) { Map hubContent = new HashMap<>(); - Collection objectTypes = metamodelService.getObjectTypes(repository, hub); + Collection objectTypes = metamodelService.getObjectTypes(repository, hubName); for (TfObjectType objectType : objectTypes) { List> result = jdbcTemplate.queryForList("SELECT content from tf_objects WHERE object_type_id = " + objectType.getId()); List results = result.stream().map(e -> e.values().iterator().next()).map(e -> gson.fromJson(String.valueOf(e), Map.class)).collect(Collectors.toList()); hubContent.put(objectType.getName(), results); } hubContent.put("@schema", SchemaService.SCHEMA_URL); - String result = restTemplate.postForObject(EPICO_VALIDATION_URL, hubContent, String.class); - return gson.toJson(gson.fromJson(result, Map.class)); + TfVersion version = objectTypes.iterator().next().getVersion(); + try { + String resultJSON = restTemplate.postForObject(EPICO_VALIDATION_URL, hubContent, String.class); + Map result = gson.fromJson(resultJSON, Map.class); + version.setValidation(Boolean.TRUE.toString().equalsIgnoreCase(String.valueOf(result.get("validated")))); + versionRepository.saveAndFlush(version); + return gson.toJson(result); + } catch (Exception e) { + log.error(e.getMessage(), e); + version.setValidation(false); + versionRepository.saveAndFlush(version); + return "Validation error: " + e.getMessage(); + } } @Autowired @@ -60,6 +75,11 @@ public void setMetamodelService(MetamodelService metamodelService) { this.metamodelService = metamodelService; } + @Autowired + public void setVersionRepository(VersionRepository versionRepository) { + this.versionRepository = versionRepository; + } + @Autowired public void setRestTemplate(RestTemplate restTemplate) { this.restTemplate = restTemplate; diff --git a/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindHubsUI.java b/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindHubsUI.java index 0cd4573f..99e2d0df 100644 --- a/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindHubsUI.java +++ b/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindHubsUI.java @@ -13,11 +13,13 @@ import lombok.extern.slf4j.Slf4j; import no.uio.ifi.trackfind.backend.data.providers.DataProvider; import no.uio.ifi.trackfind.backend.pojo.TfHub; +import no.uio.ifi.trackfind.backend.pojo.TfVersion; import no.uio.ifi.trackfind.backend.services.ValidationService; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.dialogs.ConfirmDialog; import java.util.Collections; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -133,6 +135,7 @@ private VerticalLayout buildButtonsLayout() { log.error(e.getMessage(), e); Notification.show("Error: " + e.getMessage(), Notification.Type.ERROR_MESSAGE); } + listSelect.getDataProvider().refreshAll(); } })); validate = new Button("Validate"); @@ -147,8 +150,7 @@ private VerticalLayout buildButtonsLayout() { Set activeHubs = listSelect.getSelectedItems(); for (TfHub hub : activeHubs) { String result = validationService.validate(hub.getRepository(), hub.getName()); - ConfirmDialog.show(ui, result, (ConfirmDialog.Listener) d -> { - }); + ConfirmDialog.show(ui, result, (ConfirmDialog.Listener) d -> listSelect.getDataProvider().refreshAll()); } } catch (Exception e) { log.error(e.getMessage(), e); @@ -176,7 +178,18 @@ protected int sizeInBackEnd(Query query) { return (int) fetchFromBackEnd(query).count(); } }); - listSelect.setItemCaptionGenerator(h -> h.getRepository() + ": " + h.getName()); + listSelect.setItemCaptionGenerator(hub -> { + String caption = hub.getRepository() + ": " + hub.getName(); + Optional currentVersionOptional = hub.getCurrentVersion(); + if (currentVersionOptional.isPresent()) { + caption += " ⬇️"; + Boolean validation = currentVersionOptional.get().getValidation(); + if (validation != null) { + caption += (validation ? " ✅" : " ❌"); + } + } + return caption; + }); listSelect.addSelectionListener((MultiSelectionListener) event -> remove.setEnabled(!listSelect.getSelectedItems().isEmpty())); listSelect.addSelectionListener((MultiSelectionListener) event -> crawl.setEnabled(!listSelect.getSelectedItems().isEmpty())); listSelect.addSelectionListener((MultiSelectionListener) event -> validate.setEnabled(!listSelect.getSelectedItems().isEmpty())); diff --git a/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindVersionsUI.java b/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindVersionsUI.java index 3b415e5a..811fe04f 100644 --- a/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindVersionsUI.java +++ b/src/main/java/no/uio/ifi/trackfind/frontend/TrackFindVersionsUI.java @@ -83,7 +83,7 @@ public JsonValue encode(Object value) { TfUser tfUser = (TfUser) user; return tfUser == null ? null : tfUser.getFullName(); }, new TextRenderer("Auto-crawled")); - grid.setColumnOrder("version", "operation", "user", "time", "validated", "id"); + grid.setColumnOrder("version", "operation", "user", "time", "validation", "id"); grid.sort("id"); grid.setData(hub); grid.setItems(hub.getVersions()); diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 56ba5721..f30af2d0 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -54,15 +54,15 @@ CREATE TABLE IF NOT EXISTS tf_hubs CREATE TABLE IF NOT EXISTS tf_versions ( - id BIGSERIAL PRIMARY KEY, - hub_id BIGINT REFERENCES tf_hubs (id), - version BIGINT NOT NULL, - based_on BIGINT REFERENCES tf_versions (id), - current BOOLEAN NOT NULL, - operation VARCHAR NOT NULL, - user_id BIGINT REFERENCES tf_users (id), - time TIMESTAMP NOT NULL, - validated BOOLEAN NOT NULL, + id BIGSERIAL PRIMARY KEY, + hub_id BIGINT REFERENCES tf_hubs (id), + version BIGINT NOT NULL, + based_on BIGINT REFERENCES tf_versions (id), + current BOOLEAN NOT NULL, + operation VARCHAR NOT NULL, + user_id BIGINT REFERENCES tf_users (id), + time TIMESTAMP NOT NULL, + validation BOOLEAN, UNIQUE (hub_id, version), CONSTRAINT mapping_should_have_based_on CHECK ( based_on IS NOT NULL OR operation = 'CRAWLING' ) );