ajax methods for wfs

This commit is contained in:
Michele Artini 2023-03-21 12:13:23 +01:00
parent 28598ddfea
commit 806f8e9227
12 changed files with 109 additions and 39 deletions

View File

@ -40,9 +40,9 @@ public class DsmAjaxController extends AbstractDnetController {
private ProtocolService protocolService; private ProtocolService protocolService;
@GetMapping("/browsableFields") @GetMapping("/browsableFields")
public List<KeyValue> browsableFields() { public List<KeyValue<String>> browsableFields() {
return Arrays.stream(DsmBrowsableFields.values()) return Arrays.stream(DsmBrowsableFields.values())
.map(f -> new KeyValue(f.name(), f.desc)) .map(f -> new KeyValue<>(f.name(), f.desc))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -56,30 +56,30 @@ public class InfoAjaxController extends AbstractDnetController {
return res; return res;
} }
private InfoSection<KeyValue> jvm() { private InfoSection<KeyValue<String>> jvm() {
final InfoSection<KeyValue> jvm = new InfoSection<>("JVM"); final InfoSection<KeyValue<String>> jvm = new InfoSection<>("JVM");
jvm.getData().add(new KeyValue("JVM Name", mxbean.getVmName())); jvm.getData().add(new KeyValue<>("JVM Name", mxbean.getVmName()));
jvm.getData().add(new KeyValue("JVM Vendor", mxbean.getVmVendor())); jvm.getData().add(new KeyValue<>("JVM Vendor", mxbean.getVmVendor()));
jvm.getData().add(new KeyValue("JVM Version", mxbean.getVmVersion())); jvm.getData().add(new KeyValue<>("JVM Version", mxbean.getVmVersion()));
jvm.getData().add(new KeyValue("JVM Spec Name", mxbean.getSpecName())); jvm.getData().add(new KeyValue<>("JVM Spec Name", mxbean.getSpecName()));
jvm.getData().add(new KeyValue("JVM Spec Vendor", mxbean.getSpecVendor())); jvm.getData().add(new KeyValue<>("JVM Spec Vendor", mxbean.getSpecVendor()));
jvm.getData().add(new KeyValue("JVM Spec Version", mxbean.getSpecVersion())); jvm.getData().add(new KeyValue<>("JVM Spec Version", mxbean.getSpecVersion()));
jvm.getData().add(new KeyValue("Running JVM Name", mxbean.getName())); jvm.getData().add(new KeyValue<>("Running JVM Name", mxbean.getName()));
jvm.getData().add(new KeyValue("Management Spec Version", mxbean.getManagementSpecVersion())); jvm.getData().add(new KeyValue<>("Management Spec Version", mxbean.getManagementSpecVersion()));
return jvm; return jvm;
} }
private InfoSection<KeyValue> args() { private InfoSection<KeyValue<String>> args() {
final InfoSection<KeyValue> libs = new InfoSection<>("Arguments"); final InfoSection<KeyValue<String>> libs = new InfoSection<>("Arguments");
libs.getData().add(new KeyValue("Input arguments", StringUtils.join(mxbean.getInputArguments(), " "))); libs.getData().add(new KeyValue<>("Input arguments", StringUtils.join(mxbean.getInputArguments(), " ")));
return libs; return libs;
} }
private List<InfoSection<KeyValue>> props() { private List<InfoSection<KeyValue<?>>> props() {
final List<InfoSection<KeyValue>> res = new ArrayList<>(); final List<InfoSection<KeyValue<?>>> res = new ArrayList<>();
configurableEnvironment.getPropertySources().forEach(ps -> { configurableEnvironment.getPropertySources().forEach(ps -> {
final InfoSection<KeyValue> section = new InfoSection<>("Properties: " + ps.getName()); final InfoSection<KeyValue<?>> section = new InfoSection<>("Properties: " + ps.getName());
addAllProperties(section, ps); addAllProperties(section, ps);
res.add(section); res.add(section);
}); });
@ -87,13 +87,13 @@ public class InfoAjaxController extends AbstractDnetController {
return res; return res;
} }
private void addAllProperties(final InfoSection<KeyValue> res, final PropertySource<?> ps) { private void addAllProperties(final InfoSection<KeyValue<?>> res, final PropertySource<?> ps) {
if (ps instanceof CompositePropertySource) { if (ps instanceof CompositePropertySource) {
final CompositePropertySource cps = (CompositePropertySource) ps; final CompositePropertySource cps = (CompositePropertySource) ps;
cps.getPropertySources().forEach(x -> addAllProperties(res, x)); cps.getPropertySources().forEach(x -> addAllProperties(res, x));
} else if (ps instanceof EnumerablePropertySource<?>) { } else if (ps instanceof EnumerablePropertySource<?>) {
final EnumerablePropertySource<?> eps = (EnumerablePropertySource<?>) ps; final EnumerablePropertySource<?> eps = (EnumerablePropertySource<?>) ps;
Arrays.asList(eps.getPropertyNames()).forEach(k -> res.getData().add(new KeyValue(k, eps.getProperty(k)))); Arrays.asList(eps.getPropertyNames()).forEach(k -> res.getData().add(new KeyValue<>(k, eps.getProperty(k))));
} else {} } else {}
} }

View File

@ -1,11 +1,11 @@
package eu.dnetlib.is.info; package eu.dnetlib.is.info;
public class KeyValue { public class KeyValue<T> {
private final String k; private final String k;
private final Object v; private final T v;
public KeyValue(final String k, final Object v) { public KeyValue(final String k, final T v) {
this.k = k; this.k = k;
this.v = v; this.v = v;
} }
@ -14,7 +14,7 @@ public class KeyValue {
return k; return k;
} }
public Object getV() { public T getV() {
return v; return v;
} }

View File

@ -1,15 +1,17 @@
package eu.dnetlib.manager.wf; package eu.dnetlib.manager.wf;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.common.controller.AbstractDnetController; import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.is.info.KeyValue;
import eu.dnetlib.manager.wf.model.WorkflowInstance; import eu.dnetlib.manager.wf.model.WorkflowInstance;
import eu.dnetlib.utils.CountedValue;
@RestController @RestController
@RequestMapping("/ajax/wf_instances") @RequestMapping("/ajax/wf_instances")
@ -22,9 +24,18 @@ public class WfInstancesController extends AbstractDnetController {
return wfManagerService.findWorkflowInstance(id); return wfManagerService.findWorkflowInstance(id);
} }
@GetMapping("/families") @GetMapping("/search")
public List<CountedValue> listWfFamilies() throws Exception { public List<KeyValue<String>> listWfInstances(@RequestParam final String section) throws Exception {
return wfManagerService.families(); return wfManagerService.streamWfInstancesBySection(section)
.map(x -> new KeyValue<>(x.getId(), x.getName()))
.collect(Collectors.toList());
}
@GetMapping("/sections")
public List<KeyValue<Long>> listWfFamilies() throws Exception {
return wfManagerService.streamSections()
.map(x -> new KeyValue<>(x.getValue(), x.getCount()))
.collect(Collectors.toList());
} }
} }

View File

@ -38,6 +38,7 @@ import { MdstoresComponent, MdstoreInspectorComponent, MDStoreVersionsDialog, Ad
import { CleanerTesterComponent } from './cleaner-tester/cleaner-tester.component'; import { CleanerTesterComponent } from './cleaner-tester/cleaner-tester.component';
import { EmailDialog, EmailsComponent } from './emails/emails.component'; import { EmailDialog, EmailsComponent } from './emails/emails.component';
import { WfInstancesComponent } from './wf-instances/wf-instances.component'; import { WfInstancesComponent } from './wf-instances/wf-instances.component';
import { MatTabsModule } from '@angular/material/tabs';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -100,7 +101,8 @@ import { WfInstancesComponent } from './wf-instances/wf-instances.component';
ReactiveFormsModule, ReactiveFormsModule,
MatSnackBarModule, MatSnackBarModule,
MatPaginatorModule, MatPaginatorModule,
MatProgressSpinnerModule MatProgressSpinnerModule,
MatTabsModule
], ],
providers: [{ providers: [{
provide: HTTP_INTERCEPTORS, provide: HTTP_INTERCEPTORS,

View File

@ -350,6 +350,27 @@ export class ISService {
}); });
} }
loadWfIntancesSections(onSuccess: Function): void {
this.client.get<void>('./ajax/wf_instances/sections').subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
loadWfIntances(section: string, onSuccess: Function): void {
this.client.get<void>('./ajax/wf_instances/search?section=' + encodeURIComponent(section)).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
loadWfIntance(id: string, onSuccess: Function): void {
this.client.get<void>('./ajax/wf_instances/instance/' + encodeURIComponent(id)).subscribe({
next: data => onSuccess(data),
error: error => this.showError(error)
});
}
private showError(error: any, form?: FormGroup) { private showError(error: any, form?: FormGroup) {
console.log(error); console.log(error);

View File

@ -1 +1,7 @@
<p>wfs works!</p> <h2>Workflow Instances</h2>
<mat-tab-group animationDuration="0ms">
<mat-tab label="First">Content 1</mat-tab>
<mat-tab label="Second">Content 2</mat-tab>
<mat-tab label="Third">Content 3</mat-tab>
</mat-tab-group>

View File

@ -31,6 +31,12 @@ public class WorkflowInstance implements Serializable {
@Column(name = "id") @Column(name = "id")
private String id; private String id;
@Column(name = "name")
private String name;
@Column(name = "section")
private String section;
@Type(type = "jsonb") @Type(type = "jsonb")
@Column(name = "details", columnDefinition = "jsonb") @Column(name = "details", columnDefinition = "jsonb")
private Map<String, String> details = new LinkedHashMap<>(); private Map<String, String> details = new LinkedHashMap<>();
@ -87,6 +93,22 @@ public class WorkflowInstance implements Serializable {
this.id = id; this.id = id;
} }
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getSection() {
return section;
}
public void setSection(final String section) {
this.section = section;
}
public Map<String, String> getDetails() { public Map<String, String> getDetails() {
return details; return details;
} }

View File

@ -264,6 +264,8 @@ CREATE TABLE emails (
CREATE TABLE workflow_instances ( CREATE TABLE workflow_instances (
id text PRIMARY KEY, id text PRIMARY KEY,
name text NOT NULL,
section text,
details jsonb NOT NULL DEFAULT '{}', details jsonb NOT NULL DEFAULT '{}',
priority int, priority int,
dsid text, dsid text,

View File

@ -1,6 +1,6 @@
package eu.dnetlib.manager.wf.repository; package eu.dnetlib.manager.wf.repository;
import java.util.List; import java.util.stream.Stream;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
@ -10,10 +10,12 @@ import eu.dnetlib.utils.CountedValue;
public interface WorkflowInstanceRepository extends JpaRepository<WorkflowInstance, String> { public interface WorkflowInstanceRepository extends JpaRepository<WorkflowInstance, String> {
@Query(value = "select r.subtype as value, count(*) as count " @Query(value = "select section as value, count(*) as count "
+ "from workflow_instances i join resources r on (i.workflow = r.id) " + "from workflow_instances "
+ "group by r.subtype " + "group by section "
+ "order by count desc;", nativeQuery = true) + "order by count desc;", nativeQuery = true)
List<CountedValue> families(); Stream<CountedValue> streamSections();
Stream<WorkflowInstance> findBySection(String section);
} }

View File

@ -1,11 +1,11 @@
package eu.dnetlib.manager.wf; package eu.dnetlib.manager.wf;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -187,8 +187,12 @@ public class WorkflowManagerService implements Stoppable {
this.paused = paused; this.paused = paused;
} }
public List<CountedValue> families() { public Stream<CountedValue> streamSections() {
return workflowInstanceRepository.families(); return workflowInstanceRepository.streamSections();
}
public Stream<WorkflowInstance> streamWfInstancesBySection(final String section) {
return workflowInstanceRepository.findBySection(section);
} }
} }

View File

@ -75,7 +75,7 @@ public class WorkflowProcess implements Comparable<WorkflowProcess> {
} }
public String getName() { public String getName() {
return wfMetadata.getName(); return wfInstance.getName();
} }
public String getFamily() { public String getFamily() {