Skip to content

Commit

Permalink
Show icon if the hub is crawled and validated
Browse files Browse the repository at this point in the history
  • Loading branch information
dtitov committed Oct 1, 2019
1 parent ffd4860 commit 549203b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>no.uio.ifi</groupId>
<artifactId>trackfind</artifactId>
<version>2.8.0</version>
<version>2.8.1</version>
<packaging>jar</packaging>

<name>trackfind</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> hubContent = new HashMap<>();
Collection<TfObjectType> objectTypes = metamodelService.getObjectTypes(repository, hub);
Collection<TfObjectType> objectTypes = metamodelService.getObjectTypes(repository, hubName);
for (TfObjectType objectType : objectTypes) {
List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT content from tf_objects WHERE object_type_id = " + objectType.getId());
List<Map> 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<String, Object> 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
Expand All @@ -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;
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/no/uio/ifi/trackfind/frontend/TrackFindHubsUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -147,8 +150,7 @@ private VerticalLayout buildButtonsLayout() {
Set<TfHub> 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);
Expand Down Expand Up @@ -176,7 +178,18 @@ protected int sizeInBackEnd(Query<TfHub, String> query) {
return (int) fetchFromBackEnd(query).count();
}
});
listSelect.setItemCaptionGenerator(h -> h.getRepository() + ": " + h.getName());
listSelect.setItemCaptionGenerator(hub -> {
String caption = hub.getRepository() + ": " + hub.getName();
Optional<TfVersion> currentVersionOptional = hub.getCurrentVersion();
if (currentVersionOptional.isPresent()) {
caption += " ⬇️";
Boolean validation = currentVersionOptional.get().getValidation();
if (validation != null) {
caption += (validation ? " ✅" : " ❌");
}
}
return caption;
});
listSelect.addSelectionListener((MultiSelectionListener<TfHub>) event -> remove.setEnabled(!listSelect.getSelectedItems().isEmpty()));
listSelect.addSelectionListener((MultiSelectionListener<TfHub>) event -> crawl.setEnabled(!listSelect.getSelectedItems().isEmpty()));
listSelect.addSelectionListener((MultiSelectionListener<TfHub>) event -> validate.setEnabled(!listSelect.getSelectedItems().isEmpty()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
18 changes: 9 additions & 9 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
);
Expand Down

0 comments on commit 549203b

Please sign in to comment.