imported modular-ui modules, dnet-datasource-manager-common, cnr-enabling-database-api

master
Claudio Atzori 5 years ago
parent 00ff29e05f
commit c972db2ee4

@ -64,9 +64,10 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
</dependency>
<dependency>

@ -0,0 +1,103 @@
package eu.dnetlib.data.download.rmi;
import java.util.List;
import com.google.gson.Gson;
import eu.dnetlib.data.download.rmi.DownloadItem.OpenAccessValues;
import org.joda.time.DateTime;
import org.joda.time.Days;
// TODO: Auto-generated Javadoc
/**
* The Class AbstractDownloadPlugin.
*/
public abstract class AbstractDownloadPlugin {
public static final int DEFAULT_TIMEOUT = 5000;
/**
* The regular expression.
*/
protected List<String> regularExpression;
/**
* Check open access.
*
* @param input the input
* @return the download item
*/
public DownloadItem checkOpenAccess(final DownloadItem input) {
if (input != null) {
OpenAccessValues openAccess = OpenAccessValues.valueOf(input.getOpenAccess());
switch (openAccess) {
case OPEN:
return input;
case CLOSED:
case RESTRICTED:
case UNKNOWN:
return null;
case EMBARGO:
if (input.getEmbargoDate() == null) return null;
DateTime embargoDate = new DateTime(input.getEmbargoDate());
DateTime today = new DateTime();
Days days = Days.daysBetween(embargoDate, today);
if (days.getDays() <= 0) return input;
return null;
}
}
return null;
}
public DownloadItem filterByRegexp(final DownloadItem input) {
if (this.regularExpression != null && this.regularExpression.size() > 0) {
final String baseURLs = input.getUrl();
final List<String> urlsList = new Gson().fromJson(baseURLs, List.class);
for (final String baseURL : urlsList) {
for (final String regExp : regularExpression) {
if (baseURL.matches(regExp))
return input;
}
}
return null;
} else return input;
}
protected boolean checkUrlsNotNull(DownloadItem input, List<String> urls) {
for (String s : urls) {
String newURL = extractURL(s);
if (newURL != null) {
input.setOriginalUrl(s);
input.setUrl(newURL);
return true;
}
}
return false;
}
public abstract String extractURL(final String baseURL) throws DownloadPluginException;
/**
* Gets the regular expression.
*
* @return the regular expression
*/
public List<String> getRegularExpression() {
return regularExpression;
}
/**
* Sets the regular expression.
*
* @param regularExpression the new regular expression
*/
public void setRegularExpression(final List<String> regularExpression) {
this.regularExpression = regularExpression;
}
}

@ -0,0 +1,180 @@
package eu.dnetlib.data.download.rmi;
import java.util.Date;
import com.google.gson.Gson;
import eu.dnetlib.miscutils.functional.hash.Hashing;
// TODO: Auto-generated Javadoc
/**
* Download Item Class that serialize information in the resultset.
*/
public class DownloadItem {
/** The id item metadata. */
private String idItemMetadata;
/**
* The url.
*/
private String url;
/** The file name. */
private String fileName;
/** The original URL should be appear instead of the downloaded URL. */
private String originalUrl;
/** The open access. */
private OpenAccessValues openAccess;
/** The embargo date. */
private Date embargoDate;
/**
* From json.
*
* @param inputJson
* the input json
* @return the download item
*/
public static DownloadItem newObjectfromJSON(final String inputJson) {
Gson g = new Gson();
DownloadItem instance = g.fromJson(inputJson, DownloadItem.class);
return instance;
}
/**
* To json.
*
* @return the string
*/
public String toJSON() {
return new Gson().toJson(this).replace("\\u003d", "=").replace("\\u0026", "&");
}
/**
* Gets the id item metadata.
*
* @return the id item metadata
*/
public String getIdItemMetadata() {
return idItemMetadata;
}
/**
* Sets the id item metadata.
*
* @param idItemMetadata
* the new id item metadata
*/
public void setIdItemMetadata(final String idItemMetadata) {
this.idItemMetadata = idItemMetadata;
}
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() {
if (url == null) return url;
return url.replace("\\u003d", "=").replace("\\u0026", "&");
}
/**
* Sets the url.
*
* @param url
* the new url
*/
public void setUrl(final String url) {
this.url = url;
}
/**
* Gets the original url.
*
* @return the originalUrl
*/
public String getOriginalUrl() {
if (originalUrl == null) return originalUrl;
return originalUrl.replace("\\u003d", "=").replace("\\u0026", "&");
}
/**
* Sets the original url.
*
* @param originalUrl
* the originalUrl to set
*/
public void setOriginalUrl(final String originalUrl) {
this.originalUrl = originalUrl;
}
/**
* Gets the file name.
*
* @return the file name
*/
public String getFileName() {
if ((fileName == null) || "".equals(fileName)) return getIdItemMetadata() + "::" + Hashing.md5(getOriginalUrl());
return fileName;
}
/**
* Sets the file name.
*
* @param fileName
* the new file name
*/
public void setFileName(final String fileName) {
this.fileName = fileName;
}
/**
* Gets the open access.
*
* @return the openAccess
*/
public String getOpenAccess() {
return openAccess.toString();
}
/**
* Sets the open access.
*
* @param openAccess
* the openAccess to set
*/
public void setOpenAccess(final String openAccess) {
for (OpenAccessValues oaValue : OpenAccessValues.values()) {
if (oaValue.toString().trim().toLowerCase().equals(openAccess.trim().toLowerCase())) {
this.openAccess = oaValue;
return;
}
}
this.openAccess = OpenAccessValues.UNKNOWN;
}
/**
* Gets the embargo date.
*
* @return the embargoDate
*/
public Date getEmbargoDate() {
return embargoDate;
}
/**
* Sets the embargo date.
*
* @param embargoDate
* the embargoDate to set
*/
public void setEmbargoDate(final Date embargoDate) {
this.embargoDate = embargoDate;
}
public enum OpenAccessValues {
OPEN, RESTRICTED, CLOSED, EMBARGO, UNKNOWN
}
}

@ -0,0 +1,54 @@
package eu.dnetlib.data.download.rmi;
import java.util.List;
/**
* The DownloadPluin should retrieve the correct URL of the file to download
*/
public interface DownloadPlugin {
/**
* If Sets the base path, the plugin will start to download from the basePath in the file system
*
* @param basePath the base path
*/
void setBasePath(String basePath);
/**
* This method retrieve the correct Url of the file from the starting URL
*
* @param item the starting url
* @return the Url of the correct file
*/
DownloadItem retrieveUrl(DownloadItem item) throws DownloadPluginException;
/**
* This method retrieve the correct Url of the file from a list of starting URL
*
* @param items the list of starting url
* @return the list of the file URL
*/
Iterable<DownloadItem> retrieveUrls(Iterable<DownloadItem> items) throws DownloadPluginException;
/**
* Get the name of the plugin
*
* @return the name of the plugin
*/
String getPluginName();
/**
* Gets the regular expression.
*
* @return the regular expression
*/
List<String> getRegularExpression();
/**
* Sets the regular expression.
*
* @param regularExpression the new regular expression
*/
void setRegularExpression(final List<String> regularExpression);
}

@ -0,0 +1,23 @@
package eu.dnetlib.data.download.rmi;
import java.util.Map;
import org.springframework.beans.factory.BeanFactoryAware;
public interface DownloadPluginEnumerator extends BeanFactoryAware {
/**
* Get all beans implementing the DownloadPlugin interface, hashed by name.
*
* @return the map of available download plugins
*/
Map<String, DownloadPlugin> getAll();
/**
* Get all beans implementing the DownloadPlugin interface, hashed by protocol name.
*
* @return the map of available download plugins
*/
Map<String, DownloadPlugin> getByProtocols();
}

@ -0,0 +1,23 @@
package eu.dnetlib.data.download.rmi;
public class DownloadPluginException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = -8480343562060711656L;
public DownloadPluginException(final String string, final Throwable exception) {
super(string, exception);
}
public DownloadPluginException(final Throwable exception) {
super(exception);
}
public DownloadPluginException(final String msg) {
super(msg);
}
}

@ -0,0 +1,36 @@
package eu.dnetlib.data.download.rmi;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import eu.dnetlib.common.rmi.BaseService;
/**
*
*/
@WebService(targetNamespace = "http://services.dnetlib.eu/")
public interface DownloadService extends BaseService {
/**
* Download the file in the resultset to the objectStore.
*
* @param resultSet
* the resultset of the url Object
* @param plugin
* the name of the plugin to be applied to retrieve the URL
* @param objectStoreID
* the object store id where download the file
* @throws DownloadServiceException
* the download service exception
*/
@WebMethod(operationName = "downloadFromResultSet", action = "downloadFromResultSet")
public void downloadFromResultSet(W3CEndpointReference resultSet, String plugin, String objectStoreID, String protocol, String mimeType)
throws DownloadServiceException;
@WebMethod(operationName = "listPlugins", action = "listPlugins")
public List<String> listPlugins() throws DownloadServiceException;
}

@ -0,0 +1,24 @@
package eu.dnetlib.data.download.rmi;
import eu.dnetlib.common.rmi.RMIException;
public class DownloadServiceException extends RMIException {
/**
*
*/
private static final long serialVersionUID = -5031281288958769185L;
public DownloadServiceException(final String string) {
super(string);
}
public DownloadServiceException(final String string, final Throwable exception) {
super(string, exception);
}
public DownloadServiceException(final Throwable exception) {
super(exception);
}
}

@ -1,9 +1,9 @@
package eu.dnetlib.data.objectstore.rmi;
import java.io.Serializable;
import com.google.gson.Gson;
import java.io.Serializable;
public class MetadataObjectRecord implements Serializable {
/** The Constant serialVersionUID. */

@ -1,9 +1,9 @@
package eu.dnetlib.data.objectstore.rmi;
import java.io.Serializable;
import com.google.gson.Gson;
import java.io.Serializable;
/**
* The Class ObjectStoreFile.
*/

@ -1,13 +1,12 @@
package eu.dnetlib.data.objectstore.rmi;
import java.util.List;
import eu.dnetlib.common.rmi.BaseService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import eu.dnetlib.common.rmi.BaseService;
import java.util.List;
/**
* Main ObjectStore Service interface.

@ -1,10 +1,10 @@
package eu.dnetlib.data.utility.cleaner.rmi;
import eu.dnetlib.common.rmi.BaseService;
import javax.jws.WebService;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import eu.dnetlib.common.rmi.BaseService;
/**
* @author michele
*

@ -0,0 +1,23 @@
package eu.dnetlib.enabling.database.rmi;
import eu.dnetlib.common.rmi.RMIException;
public class DatabaseException extends RMIException {
/**
*
*/
private static final long serialVersionUID = -8464953372238046419L;
public DatabaseException(Throwable cause) {
super(cause);
}
public DatabaseException(String message, Throwable cause) {
super(message, cause);
}
public DatabaseException(String message) {
super(message);
}
}

@ -0,0 +1,55 @@
package eu.dnetlib.enabling.database.rmi;
import java.util.Date;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import eu.dnetlib.common.rmi.BaseService;
@WebService(targetNamespace = "http://services.dnetlib.eu/")
public interface DatabaseService extends BaseService {
@WebMethod(operationName = "dumpTable")
W3CEndpointReference dumpTable(@WebParam(name = "db") String db, @WebParam(name = "table") String table) throws DatabaseException;
@WebMethod(operationName = "dumpTableAndLogs")
W3CEndpointReference dumpTableAndLogs(
@WebParam(name = "db") String db,
@WebParam(name = "table") String table,
@WebParam(name = "from") Date from,
@WebParam(name = "until") Date until) throws DatabaseException;
@WebMethod(operationName = "importFromEPR")
void importFromEPR(@WebParam(name = "db") String db, @WebParam(name = "epr") W3CEndpointReference epr, @WebParam(name = "xslt") String xslt)
throws DatabaseException;
@WebMethod(operationName = "searchSQL")
W3CEndpointReference searchSQL(@WebParam(name = "db") String db, @WebParam(name = "sql") String sql) throws DatabaseException;
@WebMethod(operationName = "alternativeSearchSQL")
W3CEndpointReference alternativeSearchSQL(@WebParam(name = "db") String db,
@WebParam(name = "sql") String sql,
@WebParam(name = "sqlForSize") String sqlForSize) throws DatabaseException;
@WebMethod(operationName = "updateSQL")
void updateSQL(@WebParam(name = "db") String db, @WebParam(name = "sql") String sql) throws DatabaseException;
@WebMethod(operationName = "xsltSearchSQL")
W3CEndpointReference xsltSearchSQL(@WebParam(name = "db") String db, @WebParam(name = "sql") String sql, @WebParam(name = "xslt") String xslt)
throws DatabaseException;
@WebMethod(operationName = "alternativeXsltSearchSQL")
W3CEndpointReference alternativeXsltSearchSQL(@WebParam(name = "db") String db,
@WebParam(name = "sql") String sql,
@WebParam(name = "sqlForSize") String sqlForSize,
@WebParam(name = "xslt") String xslt) throws DatabaseException;
@WebMethod(operationName = "contains")
boolean contains(@WebParam(name = "db") String db,
@WebParam(name = "table") String table,
@WebParam(name = "column") String column,
@WebParam(name = "value") String value) throws DatabaseException;
}

@ -0,0 +1,18 @@
package eu.dnetlib.data.download.rmi;
import junit.framework.Assert;
/**
* Created by sandro on 3/21/14.
*/
public class DownloadItemTest {
@org.junit.Test
public void testGetFileName() throws Exception {
DownloadItem di = new DownloadItem();
di.setIdItemMetadata("id1");
di.setUrl("http://www.test.com");
di.setFileName("testFile");
Assert.assertEquals("testFile", di.getFileName());
}
}

@ -12,6 +12,7 @@
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-core-components</artifactId>

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>dnet-modular-ui</artifactId>
<groupId>eu.dnetlib</groupId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-core-components</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-information-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-data-services</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-msro-service</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,64 @@
package eu.dnetlib.data.transformation.ui;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import eu.dnetlib.data.transformation.service.DataTransformerFactory;
import eu.dnetlib.data.transformation.service.SimpleDataTransformer;
import eu.dnetlib.enabling.inspector.AbstractInspectorController;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.functionality.modular.ui.error.ErrorMessage;
@Controller
public class DataTransformationController extends AbstractInspectorController {
@Resource
private DataTransformerFactory dataTransformerFactory;
@Resource
private TransformerUtils transformerUtils;
@RequestMapping(value = "/inspector/transform.do")
public void transform(final Model model,
@RequestParam(value = "rule", required = false) final String ruleId,
@RequestParam(value = "record", required = false) final String record) throws Exception {
model.addAttribute("rules", transformerUtils.obtainRuleProfiles(ruleId));
if (ruleId != null && record != null) {
final SimpleDataTransformer transformer = dataTransformerFactory.createTransformer(ruleId);
model.addAttribute("input", record);
model.addAttribute("output", transformer.evaluate(record));
}
}
@RequestMapping(value = "/ui/transform/transform.do")
public void transform(final HttpServletResponse res,
@RequestParam(value = "rule", required = true) final String ruleId,
@RequestBody final String record) throws ISLookUpDocumentNotFoundException, ISLookUpException, IOException {
res.setContentType("text/xml");
IOUtils.write(dataTransformerFactory.createTransformer(ruleId).evaluate(record), res.getOutputStream());
}
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public @ResponseBody ErrorMessage handleException(final HttpServletRequest req, final Exception e) {
return new ErrorMessage(e.getMessage(), ExceptionUtils.getStackTrace(e));
}
}

@ -0,0 +1,31 @@
package eu.dnetlib.data.transformation.ui;
public class SelectOption implements Comparable<SelectOption> {
private final String id;
private final String name;
private final boolean selected;
public SelectOption(final String id, final String name, final boolean selected) {
this.id = id;
this.name = name;
this.selected = selected;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public boolean isSelected() {
return selected;
}
@Override
public int compareTo(final SelectOption o) {
return getName().toLowerCase().compareTo(o.getName().toLowerCase());
}
}

@ -0,0 +1,21 @@
package eu.dnetlib.data.transformation.ui;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class TransformEntryPointController extends ModuleEntryPoint {
@Resource
private TransformerUtils transformerUtils;
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
map.addAttribute("rules", transformerUtils.obtainRuleProfiles(null));
}
}

@ -0,0 +1,38 @@
package eu.dnetlib.data.transformation.ui;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
@Component
public class TransformerUtils {
@Resource
private UniqueServiceLocator serviceLocator;
public List<SelectOption> obtainRuleProfiles(final String currentId) throws ISLookUpException {
final String xquery = "for $x " +
"in collection('/db/DRIVER/TransformationRuleDSResources/TransformationRuleDSResourceType') " +
"return concat($x//RESOURCE_IDENTIFIER/@value, ' @@@ ', $x//TITLE)";
return serviceLocator.getService(ISLookUpService.class)
.quickSearchProfile(xquery)
.stream()
.map(s -> {
final String[] arr = s.split("@@@");
final String id = arr[0].trim();
final String name = arr[1].trim();
return new SelectOption(id, name, id.equals(currentId));
})
.sorted()
.collect(Collectors.toList());
}
}

@ -0,0 +1,18 @@
package eu.dnetlib.functionality.modular.ui;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import eu.dnetlib.functionality.modular.ui.error.ErrorMessage;
public abstract class AbstractAjaxController {
@ExceptionHandler(Exception.class)
@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
public @ResponseBody ErrorMessage handleException(final Exception e) {
return ErrorMessage.newInstance(e);
}
}

@ -0,0 +1,31 @@
package eu.dnetlib.functionality.modular.ui;
import java.util.List;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Required;
public abstract class AbstractMenu implements Comparable<AbstractMenu> {
private String title;
abstract public int getOrder();
abstract public List<? extends MenuEntry> getEntries();
@Override
public int compareTo(final AbstractMenu menu) {
return NumberUtils.compare(getOrder(), menu.getOrder());
}
public String getTitle() {
return title;
}
@Required
public void setTitle(String title) {
this.title = title;
}
}

@ -0,0 +1,62 @@
package eu.dnetlib.functionality.modular.ui;
import java.io.StringReader;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.google.gson.Gson;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
@Controller
public class CommonController {
@Resource
private UniqueServiceLocator serviceLocator;
@RequestMapping(value = "/ui/**/getProfile")
public void getProfile(final HttpServletResponse res,
@RequestParam(value = "id", required = true) final String id) throws Exception {
res.setContentType("text/xml");
String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(id);
IOUtils.copy(new StringReader(profile), res.getOutputStream());
}
@RequestMapping(value = "/ui/**/getSchema")
public void getSchema(final HttpServletResponse res,
@RequestParam(value = "name", required = true) final String name) throws Exception {
res.setContentType("text/xml");
String schema = serviceLocator.getService(ISLookUpService.class).getResourceTypeSchema(name);
IOUtils.copy(new StringReader(schema), res.getOutputStream());
}
@RequestMapping(value = "/ui/**/validateProfile")
public void validate(final HttpServletResponse res,
@RequestParam(value = "id", required = true) final String id) throws Exception {
String newId = serviceLocator.getService(ISRegistryService.class).validateProfile(id);
IOUtils.copy(new StringReader(new Gson().toJson(newId)), res.getOutputStream());
}
@RequestMapping(value = "/ui/**/invalidateProfile")
public void invalidateProfile(final HttpServletResponse res,
@RequestParam(value = "id", required = true) final String id) throws Exception {
String newId = serviceLocator.getService(ISRegistryService.class).invalidateProfile(id);
IOUtils.copy(new StringReader(new Gson().toJson(newId)), res.getOutputStream());
}
@RequestMapping(value = "/ui/**/deleteProfile")
public void deleteProfile(final HttpServletResponse res,
@RequestParam(value = "id", required = true) final String id) throws Exception {
boolean b = serviceLocator.getService(ISRegistryService.class).deleteProfile(id);
IOUtils.copy(new StringReader(new Gson().toJson(b)), res.getOutputStream());
}
}

@ -0,0 +1,134 @@
package eu.dnetlib.functionality.modular.ui;
import com.google.common.collect.Maps;
import eu.dnetlib.conf.PropertyFetcher;
import eu.dnetlib.conf.WebappContextPropertyLocationFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jparsec.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.ui.ModelMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
/**
* Modular UI that displays collected properties and shows winning ones.
*
* @author Andrea Mannocci
*/
public class ContainerPropertiesController extends ModuleEntryPoint {
private static final Log log = LogFactory.getLog(ContainerPropertiesController.class);
private final ResourcePatternResolver pathResolver = new PathMatchingResourcePatternResolver();
@Autowired
private PropertyFetcher propertyFetcher;
private Properties propertyFetcherProps;
@Autowired
private WebappContextPropertyLocationFactory propertyLocations;
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
propertyFetcherProps = propertyFetcher.getProps();
map.addAttribute("properties", fetchProperties());
}
private Map<String, List<PropertyInfo>> fetchProperties() throws IOException {
final Map<String, List<PropertyInfo>> propertiesMap = Maps.newTreeMap();
// cycle over all property locations know to dnet
for (String location : propertyLocations.getLocations()) {
log.debug(String.format("Loading properties from %s", location));
// loop over all *.properties files matching the location
for (Resource propertyFile : pathResolver.getResources(location)) {
Properties properties = new Properties();
log.debug(String.format("URL: %s", propertyFile.getURL()));
properties.load(propertyFile.getInputStream());
// loop over all properties set within a property file file
for (Entry<Object, Object> property : properties.entrySet()) {
List<PropertyInfo> propertyInfoList;
if (propertiesMap.containsKey(property.getKey())) {
propertyInfoList = propertiesMap.get(property.getKey());
} else {
propertyInfoList = Lists.arrayList();
}
propertyInfoList.add(new PropertyInfo((String) property.getValue(), propertyFile.getFilename(), isWinning((String) property.getKey(), (String) property.getValue())));
propertiesMap.put((String) property.getKey(), propertyInfoList);
}
}
}
// Scans the Map just created for properties overridden externally (e.g. by Tomcat)
/* for (String property : propertiesMap.keySet()) {
List<PropertyInfo> propertyInfoList = propertiesMap.get(property);
boolean isOverridden = true;
for (PropertyInfo propInfo : propertyInfoList) {
// Checks for a checker
if (propInfo.isChecked) {
isOverridden = false;
}
}
// If none of the pairs has been checked, then the property has been overridden externally.
if (isOverridden && propertyFetcherProps.getProperty(property) != null) {
// Adds the current property value (which is the override) as the current one.
propertyInfoList.add(new PropertyInfo(propertyFetcherProps.getProperty(property), "Overridden externally", true));
propertiesMap.put(property, propertyInfoList);
}
}*/
return propertiesMap;
}
/**
* Checks whether a given property-value is the one currently in use.
*
* @param property The property key
* @param value The property value
* @return true/false
*/
private Boolean isWinning(final String property, final String value) {
String winningPropertyValue = propertyFetcherProps.getProperty(property);
return value.equals(winningPropertyValue);
}
private class PropertyInfo {
String value;
String sourcePropertyFile;
Boolean isChecked;
public PropertyInfo(final String value, final String sourcePropertyFile, final Boolean isChecked) {
this.value = value;
this.sourcePropertyFile = sourcePropertyFile;
this.isChecked = isChecked;
}
public String getValue() {
return value;
}
public String getSourcePropertyFile() {
return sourcePropertyFile;
}
public Boolean getIsChecked() {
return isChecked;
}
}
}

@ -0,0 +1,74 @@
package eu.dnetlib.functionality.modular.ui;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List;
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import eu.dnetlib.functionality.modular.ui.utils.LogLine;
import eu.dnetlib.functionality.modular.ui.utils.LogUiAppender;
@Controller
public class DnetLogAjaxController {
private LogUiAppender appender;
private static final Log log = LogFactory.getLog(DnetLogAjaxController.class);
@PostConstruct
void init() throws IOException {
this.appender = findLogUiAppender();
}
private LogUiAppender findLogUiAppender() {
final Logger logger = LogManager.getRootLogger();
final Enumeration<?> appenders = logger.getAllAppenders();
while (appenders.hasMoreElements()) {
final Object app = appenders.nextElement();
if (app instanceof LogUiAppender) {
log.info("An istance of LogUiAppender is already registered in log4j configuration.");
return (LogUiAppender) app;
}
}
final LogUiAppender app = new LogUiAppender();
LogManager.getRootLogger().addAppender(app);
log.info("A new LogUiAppender has been registered in log4j configuration.");
return app;
}
@RequestMapping(value = "/ui/log/tail/{n}")
public @ResponseBody
List<LogLine> tail_N(@PathVariable(value = "n") final int n) throws Exception {
return appender.tail_N(n);
}
@RequestMapping(value = "/ui/log/continue/{after}")
public @ResponseBody
List<LogLine> tail_continue(@PathVariable(value = "after") final int after) throws Exception {
return appender.tail_continue(after);
}
@RequestMapping(value = "/ui/log/level/{level}/{resource}")
public @ResponseBody
boolean updateLogLevel(@PathVariable(value = "level") final String level, @PathVariable(value = "resource") final String resource) throws Exception {
if (resource != null && level != null) {
LogManager.getLogger(resource).setLevel(Level.toLevel(level));
}
return true;
}
}

@ -0,0 +1,30 @@
package eu.dnetlib.functionality.modular.ui;
import java.io.File;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.FileAppender;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.ui.ModelMap;
public class DnetLogController extends ModuleEntryPoint {
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
map.addAttribute("logFile", getLogFileName());
}
public static String getLogFileName() {
final Logger logger = LogManager.getRootLogger();
final Enumeration<?> appenders = logger.getAllAppenders();
while (appenders.hasMoreElements()) {
final Object app = appenders.nextElement();
if (app instanceof FileAppender) { return new File(((FileAppender) app).getFile()).getAbsolutePath(); }
}
return "";
}
}

@ -0,0 +1,72 @@
package eu.dnetlib.functionality.modular.ui;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import eu.dnetlib.functionality.modular.ui.users.AccessLimited;
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
import eu.dnetlib.functionality.modular.ui.users.User;
public class EntryPointsAggregator {
@Autowired(required=false)
private List<ModuleEntryPoint> entryPoints = Lists.newArrayList();;
@Autowired(required=false)
private List<AbstractMenu> otherMenus = Lists.newArrayList();
public List<ModuleEntryPoint> getEntryPoints() {
return entryPoints;
}
public void setEntryPoints(List<ModuleEntryPoint> entryPoints) {
this.entryPoints = entryPoints;
}
public List<AbstractMenu> getMenus(User user) {
final Map<String, ModulesMenu> map = new HashMap<String, ModulesMenu>();
for (ModuleEntryPoint entry : entryPoints) {
if (entry.isValidMenuEntry() && verifyAuthorization(entry, user)) {
final String group = entry.getGroup();
if (!map.containsKey(group)) {
map.put(group, new ModulesMenu(group));
}
map.get(group).addEntry(entry);
}
}
final List<AbstractMenu> items = Lists.newArrayList();
for (AbstractMenu menu : otherMenus) {
if (menu instanceof AccessLimited) {
if (verifyAuthorization((AccessLimited) menu, user) && menu.getEntries().size() > 0) {
items.add(menu);
}
} else if (menu.getEntries().size() > 0) {
items.add(menu);
}
}
for (ModulesMenu item : map.values()) {
item.complete();
items.add(item);
}
Collections.sort(items);
return items;
}
private boolean verifyAuthorization(AccessLimited entry, User user) {
if (user.getPermissionLevels().contains(PermissionLevel.SUPER_ADMIN)) return true;
return (Sets.intersection(user.getPermissionLevels(), entry.getPermissionLevels()).size() > 0);
}
}

@ -0,0 +1,192 @@
package eu.dnetlib.functionality.modular.ui;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.ui.ModelMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import eu.dnetlib.miscutils.datetime.DateUtils;
import eu.dnetlib.miscutils.datetime.HumanTime;
public class InfoController extends ModuleEntryPoint implements ResourceLoaderAware {
private String hostname;
private String port;
private String context;
private ResourceLoader resourceLoader;
private static final Log log = LogFactory.getLog(InfoController.class);
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
final Map<String, Map<String, String>> info = Maps.newLinkedHashMap();
info.put("General", getGeneralInfo(mxbean));
info.put("JVM", getJvmInfo(mxbean));
info.put("Libraries and arguments", getLibInfo(mxbean));
info.put("System properties", getSysInfo(mxbean));
map.addAttribute("info", info);
map.addAttribute("modules", getModules());
}
@SuppressWarnings("unchecked")
private List<Map<String, Object>> getModules() throws IOException {
final Map<String, Map<String, Map<String, Object>>> modules = Maps.newLinkedHashMap();
final MavenXpp3Reader reader = new MavenXpp3Reader();
for (Resource res : ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath*:/META-INF/**/pom.xml")) {
try {
final Model model = reader.read(res.getInputStream());
final String name = model.getArtifactId();
String groupId = model.getGroupId();
for (Parent parent = model.getParent(); groupId == null && model.getParent() != null; parent = model.getParent()) {
groupId = parent.getGroupId();
}
String version = model.getVersion();
for (Parent parent = model.getParent(); version == null && model.getParent() != null; parent = model.getParent()) {
version = parent.getVersion();
}
if (!modules.containsKey(groupId)) {
modules.put(groupId, new HashMap<String, Map<String, Object>>());
}
if (!modules.get(groupId).containsKey(name)) {
final Map<String, Object> map = Maps.newHashMap();
map.put("group", groupId);
map.put("name", name);
map.put("files", new ArrayList<String>());
map.put("versions", new ArrayList<String>());
modules.get(groupId).put(name, map);
} else {
// Artifact already found
modules.get(groupId).get(name).put("warning", "1");
}
((List<String>) modules.get(groupId).get(name).get("versions")).add(version);
((List<String>) modules.get(groupId).get(name).get("files")).add(res.getURI().toString());
} catch (Exception e) {
log.error("Error evaluating pom: " + res.getURI());
log.debug("-- ERROR --", e);
}
}
final List<Map<String, Object>> list = Lists.newArrayList();
for (Entry<String, Map<String, Map<String, Object>>> e : modules.entrySet()) {
for (Entry<String, Map<String, Object>> e1 : e.getValue().entrySet()) {
list.add(e1.getValue());
}
}
Collections.sort(list, new Comparator<Map<String, Object>>() {
@Override
public int compare(final Map<String, Object> o1, final Map<String, Object> o2) {
if (o1.get("group").equals(o2.get("group"))) {
return o1.get("name").toString().compareTo(o2.get("name").toString());
} else {
return o1.get("group").toString().compareTo(o2.get("group").toString());
}
}
});
return list;
}
private Map<String, String> getSysInfo(final RuntimeMXBean mxbean) {
return mxbean.getSystemProperties();
}
private Map<String, String> getGeneralInfo(final RuntimeMXBean mxbean) {
final Map<String, String> genInfo = Maps.newLinkedHashMap();
genInfo.put("Hostname", hostname);
genInfo.put("Port", port);
genInfo.put("Context", context);
genInfo.put("Uptime", HumanTime.exactly(mxbean.getUptime()));
genInfo.put("Start Time", DateUtils.calculate_ISO8601(mxbean.getStartTime()));
return genInfo;
}
private Map<String, String> getJvmInfo(final RuntimeMXBean mxbean) {
final Map<String, String> jvmInfo = Maps.newLinkedHashMap();
jvmInfo.put("JVM Name", mxbean.getVmName());
jvmInfo.put("JVM Vendor", mxbean.getVmVendor());
jvmInfo.put("JVM Version", mxbean.getVmVersion());
jvmInfo.put("JVM Spec Name", mxbean.getSpecName());
jvmInfo.put("JVM Spec Vendor", mxbean.getSpecVendor());
jvmInfo.put("JVM Spec Version", mxbean.getSpecVersion());
jvmInfo.put("Running JVM Name", mxbean.getName());
jvmInfo.put("Management Spec Version", mxbean.getManagementSpecVersion());
return jvmInfo;
}
private Map<String, String> getLibInfo(final RuntimeMXBean mxbean) {
final Map<String, String> libInfo = Maps.newLinkedHashMap();
libInfo.put("Classpath", mxbean.getClassPath().replaceAll(":", " : "));
libInfo.put("Boot ClassPath", mxbean.getBootClassPath().replaceAll(":", " : "));
libInfo.put("Input arguments", mxbean.getInputArguments().toString());
libInfo.put("Library Path", mxbean.getLibraryPath().replaceAll(":", " : "));
return libInfo;
}
public String getHostname() {
return hostname;
}
@Required
public void setHostname(final String hostname) {
this.hostname = hostname;
}
public String getPort() {
return port;
}
@Required
public void setPort(final String port) {
this.port = port;
}
public String getContext() {
return context;
}
@Required
public void setContext(final String context) {
this.context = context;
}
@Override
public void setResourceLoader(final ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
}

@ -0,0 +1,13 @@
package eu.dnetlib.functionality.modular.ui;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
public class MainController extends ModuleEntryPoint {
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) {}
}

@ -0,0 +1,69 @@
package eu.dnetlib.functionality.modular.ui;
import java.util.Set;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Required;
import eu.dnetlib.functionality.modular.ui.users.AccessLimited;
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
public abstract class MenuEntry implements Comparable<MenuEntry>, AccessLimited {
private String menu;
private String title;
private String description;
private int order = 50;
private Set<PermissionLevel> permissionLevels;
@Override
public int compareTo(MenuEntry o) {
return NumberUtils.compare(this.getOrder(), o.getOrder());
}
abstract public String getRelativeUrl();
public String getMenu() {
return menu;
}
@Required
public void setMenu(String menu) {
this.menu = menu;
}
public String getTitle() {
return title;
}
@Required
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
@Required
public void setDescription(String description) {
this.description = description;
}
@Override
public Set<PermissionLevel> getPermissionLevels() {
return permissionLevels;
}
@Required
public void setPermissionLevels(Set<PermissionLevel> permissionLevels) {
this.permissionLevels = permissionLevels;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
}

@ -0,0 +1,151 @@
package eu.dnetlib.functionality.modular.ui;
import java.net.URLEncoder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.view.RedirectView;
import eu.dnetlib.functionality.modular.ui.users.AuthorizationManager;
import eu.dnetlib.functionality.modular.ui.users.User;
import eu.dnetlib.functionality.modular.ui.utils.ShutdownUtils;
public abstract class ModuleEntryPoint extends MenuEntry implements Controller, BeanNameAware {
private String beanName;
private boolean validMenuEntry = true;
private String group;
private int groupOrder = 50;
@Value("${dnet.modular.ui.authentication.url}")
private String authenticationUrl;
@Value("${dnet.modular.ui.logout.url}")
private String logoutUrl;
@Value("${dnet.modular.ui.ribbon.environment}")
private String environment;
@Value("${dnet.modular.ui.ribbon.accent}")
private String ribbonAccent;
@Resource
protected EntryPointsAggregator aggregator;
@Resource
private ShutdownUtils shutdownUtils;
@Resource(name = "modularUiAuthorizationManager")
protected AuthorizationManager authorizationManager;
@Override
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final User user = authorizationManager.obtainUserDetails(request);
if (user != null) {
final ModelAndView mv = new ModelAndView();
final ModelMap map = mv.getModelMap();
map.addAttribute("ui_menu", getMenu());
map.addAttribute("ui_title", getTitle());
map.addAttribute("ui_description", getDescription());
map.addAttribute("ui_group", getGroup());
map.addAttribute("ui_modules", aggregator.getMenus(user));
map.addAttribute("environment", environment);
map.addAttribute("ribbonAccent", ribbonAccent);
switch (shutdownUtils.currentStatus()) {
case STOPPING:
map.addAttribute("ui_navbar_class", "navbar-system-stopping");
map.addAttribute("ui_message", "stopping system");
break;
case STOPPED:
map.addAttribute("ui_navbar_class", "navbar-system-stopped");
map.addAttribute("ui_message", "system stopped");
break;
default:
map.addAttribute("ui_navbar_class", "navbar-inverse");
break;
}
String baseUrl = "";
for (int i = 1; i < StringUtils.countMatches(beanName, "/"); i++) {
baseUrl += "/..";
}
if (baseUrl.length() > 0) {
baseUrl = baseUrl.substring(1);
}
map.addAttribute("ui_baseUrl", baseUrl);
if ((logoutUrl != null) && !logoutUrl.isEmpty()) {
map.addAttribute("ui_logoutUrl", logoutUrl);
}
map.addAttribute("ui_user", user);
initialize(map, request, response);
return mv;
} else {
final StringBuffer url = request.getRequestURL();
final String queryString = request.getQueryString();
if (queryString != null) {
url.append('?');
url.append(queryString);
}
return new ModelAndView(new RedirectView(authenticationUrl + "?url=" + URLEncoder.encode(url.toString(), "UTF-8")));
}
}
abstract protected void initialize(ModelMap map, HttpServletRequest request, HttpServletResponse response) throws Exception;
public String getBeanName() {
return beanName;
}
@Override
public void setBeanName(final String beanName) {
this.beanName = beanName;
}
public String getGroup() {
return group;
}
@Required
public void setGroup(final String group) {
this.group = group;
}
@Override
public String getRelativeUrl() {
return beanName;
}
public boolean isValidMenuEntry() {
return validMenuEntry;
}
public void setValidMenuEntry(final boolean validMenuEntry) {
this.validMenuEntry = validMenuEntry;
}
public int getGroupOrder() {
return groupOrder;
}
public void setGroupOrder(final int groupOrder) {
this.groupOrder = groupOrder;
}
}

@ -0,0 +1,41 @@
package eu.dnetlib.functionality.modular.ui;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
public class ModulesMenu extends AbstractMenu {
private int order = Integer.MAX_VALUE;
private List<ModuleEntryPoint> entries = Lists.newArrayList();
public ModulesMenu(final String title) {
super();
setTitle(title);
}
public void addEntry(final ModuleEntryPoint entry) {
entries.add(entry);
}
public void complete() {
Collections.sort(entries);
for (ModuleEntryPoint e : entries) {
if (e.getGroupOrder() < this.order) {
this.order = e.getGroupOrder();
}
}
}
@Override
public int getOrder() {
return order;
}
@Override
public List<? extends MenuEntry> getEntries() {
return entries;
}
}

@ -0,0 +1,13 @@
package eu.dnetlib.functionality.modular.ui;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
public class PrepareShutdownController extends ModuleEntryPoint {
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {}
}

@ -0,0 +1,40 @@
package eu.dnetlib.functionality.modular.ui;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import eu.dnetlib.enabling.common.StoppableDetails;
import eu.dnetlib.functionality.modular.ui.utils.ShutdownUtils;
@Controller
public class PrepareShutdownInternalController {
@Resource
private ShutdownUtils shutdownUtils;
@RequestMapping("/ui/shutdown/listStoppableDetails.json")
public @ResponseBody
List<StoppableDetails> listStoppableDetails() {
return shutdownUtils.listStoppableDetails();
}
@RequestMapping("/ui/shutdown/stopAll.do")
public @ResponseBody
boolean stopAll() {
shutdownUtils.stopAll();
return true;
}
@RequestMapping("/ui/shutdown/resumeAll.do")
public @ResponseBody
boolean resumeAll() {
shutdownUtils.resumeAll();
return true;
}
}

@ -0,0 +1,13 @@
package eu.dnetlib.functionality.modular.ui;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
public class UserDetailsController extends ModuleEntryPoint {
@Override
protected void initialize(ModelMap map, HttpServletRequest request, HttpServletResponse response) throws Exception {}
}

@ -0,0 +1,38 @@
package eu.dnetlib.functionality.modular.ui;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
public class UsersController extends ModuleEntryPoint {
private List<Map<String, String>> listAvailableLevels = Lists.newArrayList();;
@Override
protected void initialize(ModelMap map, HttpServletRequest request, HttpServletResponse response) throws Exception {
map.addAttribute("availableLevels", listPermissionLevels());
}
private List<Map<String, String>> listPermissionLevels() {
if (listAvailableLevels.isEmpty()) {
for (PermissionLevel level : PermissionLevel.values()) {
final Map<String, String> map = Maps.newHashMap();
map.put("level", level.toString());
map.put("label", level.getLabel());
map.put("details", level.getDetails());
listAvailableLevels.add(map);
}
}
return listAvailableLevels;
}
}

@ -0,0 +1,60 @@
package eu.dnetlib.functionality.modular.ui;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import eu.dnetlib.functionality.modular.ui.users.AuthorizationDAO;
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
import eu.dnetlib.functionality.modular.ui.users.User;
@Controller
public class UsersInternalController {
@Resource(name="modularUiAuthorizationDao")
private AuthorizationDAO dao;
private static final Log log = LogFactory.getLog(UsersInternalController.class);
@RequestMapping(value = "/ui/users.get")
public @ResponseBody List<User> listUsers(HttpServletResponse response) throws IOException {
final List<User> list = Lists.newArrayList();
for (Map.Entry<String, Set<PermissionLevel>> e : dao.getPermissionLevels().entrySet()) {
final User user = new User(e.getKey());
user.setPermissionLevels(e.getValue());
list.add(user);
}
Collections.sort(list);
return list;
}
@RequestMapping(value = "/ui/saveusers.do", method=RequestMethod.POST)
public @ResponseBody boolean updateUsers(@RequestBody final List<User> users) {
log.info("Saving " + users.size() + " user(s)");
final Map<String, Set<PermissionLevel>> map = Maps.newHashMap();
for (User u : users) {
map.put(u.getId(), u.getPermissionLevels());
}
dao.updatePermissionLevels(map);
return true;
}
}

@ -0,0 +1,35 @@
package eu.dnetlib.functionality.modular.ui.error;
import org.apache.commons.lang.exception.ExceptionUtils;
public class ErrorMessage {
private String message;
private String stacktrace;
public ErrorMessage() {}
public static ErrorMessage newInstance(final Exception e) {
return new ErrorMessage(e.getMessage(), ExceptionUtils.getStackTrace(e));
}
public ErrorMessage(final String message, final String stacktrace) {
this.message = message;
this.stacktrace = stacktrace;
}
public String getMessage() {
return message;
}
public void setMessage(final String message) {
this.message = message;
}
public String getStacktrace() {
return stacktrace;
}
public void setStacktrace(final String stacktrace) {
this.stacktrace = stacktrace;
}
}

@ -0,0 +1,35 @@
package eu.dnetlib.functionality.modular.ui.index;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.google.common.collect.Maps;
import eu.dnetlib.functionality.index.client.IndexClient;
import eu.dnetlib.functionality.index.client.IndexClientException;
public class IndexClientMap {
private static final Log log = LogFactory.getLog(IndexClientMap.class);
private Map<String, IndexClient> map = Maps.newHashMap();
public void shutdown() throws IOException {
log.debug("shutdown index clients");
for (IndexClient client : map.values()) {
client.close();
}
}
public Map<String, IndexClient> getMap() {
return map;
}
public void setMap(final Map<String, IndexClient> map) {
this.map = map;
}
}

@ -0,0 +1,22 @@
package eu.dnetlib.functionality.modular.ui.index;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class IndexServiceEntryPointController extends ModuleEntryPoint {
@Resource
private UniqueServiceLocator serviceLocator;
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
}
}

@ -0,0 +1,287 @@
package eu.dnetlib.functionality.modular.ui.index;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import eu.dnetlib.data.provision.index.rmi.IndexServiceException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.index.client.IndexClient;
import eu.dnetlib.functionality.index.client.IndexClientException;
import eu.dnetlib.functionality.index.client.response.BrowseEntry;
import eu.dnetlib.functionality.index.client.response.LookupResponse;
import eu.dnetlib.functionality.index.client.solr.SolrIndexClientFactory;
import eu.dnetlib.functionality.modular.ui.AbstractAjaxController;
import eu.dnetlib.functionality.modular.ui.index.models.IndexInfo;
import eu.dnetlib.functionality.modular.ui.index.models.MdFormatInfo;
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* The Class IndexServiceInternalController.
*/
@Controller
public class IndexServiceInternalController extends AbstractAjaxController {
/** The Constant log. */
private static final Log log = LogFactory.getLog(IndexServiceInternalController.class);
/** The lookup locator. */
@Resource
private UniqueServiceLocator serviceLocator;
/** The index client factory. */
@Autowired
private SolrIndexClientFactory indexClientFactory;
@Autowired
private IndexClientMap clientMap;
/**
* Index metadata formats.
*
* @param map
* the map
* @return the list< md format info>
* @throws Exception
* the exception
*/
@RequestMapping(value = "/ui/index/indexMetadataFormats.do")
@ResponseBody
public List<MdFormatInfo> indexMetadataFormats(final ModelMap map) throws Exception {
final String xquery =
"for $x in //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='MDFormatDSResourceType'] "
+ "let $format:= $x//CONFIGURATION/NAME/string() for $y in $x//LAYOUTS/LAYOUT let $layout:= $y/@name/string() "
+ "let $interpretation:= $x//CONFIGURATION/INTERPRETATION/text() let $id:=$x//RESOURCE_IDENTIFIER/@value/string() "
+ " return concat($format,'-',$layout,'-',$interpretation,'::', $id) ";
log.debug("Executing lookup query" + xquery);
return quickSearchProfile(xquery).stream()
.map(MdFormatInfo::initFromXqueryResult)
.collect(Collectors.toList());
}
/**
* Index datastructures.
*
* @param backend
* the backend
* @return the list< index info>
* @throws Exception
* the exception
*/
@RequestMapping(value = "/ui/index/indexDatastructures.do")
@ResponseBody
public List<IndexInfo> indexDatastructures(@RequestParam(value = "backend", required = true) final String backend) throws Exception {
final String xquery =
"for $x in //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='IndexDSResourceType' and .//BACKEND/@ID='%s'] let $format := $x//METADATA_FORMAT "
+ "let $layout := $x//METADATA_FORMAT_LAYOUT let $interpretation :=$x//METADATA_FORMAT_INTERPRETATION "
+ "let $id :=$x//RESOURCE_IDENTIFIER/@value let $backendid := $x//BACKEND/@ID let $size := $x//INDEX_SIZE "
+ "return concat($format, ':-:',$layout,':-:',$interpretation,':-:',$id,':-:',$backendid,':-:',$size)";
log.debug("Executing lookup query" + String.format(xquery, backend));
return quickSearchProfile(String.format(xquery, backend)).stream()
.map(IndexInfo::newInstanceFromString)
.collect(Collectors.toList());
}
/**
* Md format info.
*
* @param id
* the id
* @param layout
* the layout
* @return the list< string>
* @throws Exception
* the exception
*/
@RequestMapping(value = "/ui/index/mdFormatInfo.do")
@ResponseBody
public List<String> mdFormatInfo(@RequestParam(value = "id", required = true) final String id,
@RequestParam(value = "layout", required = true) final String layout) throws Exception {
String xqueryTemplate =
"//RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='%s']" + "//LAYOUT[./@name/string()='%s'] "
+ "//FIELD[./@tokenizable/string()='false' or ./@type = 'int' or ./@type = 'date']/@name/string()";
log.debug("executing query: " + String.format(xqueryTemplate, id, layout));
return quickSearchProfile(String.format(xqueryTemplate, id, layout));
}
/**
* Gets the backend available.
*
* @return the backend available
* @throws Exception
* the exception
*/
@RequestMapping(value = "/ui/index/backend.do")
@ResponseBody
public Set<String> getBackendAvailable() throws Exception {
String xquery = "for $x in //RESOURCE_PROFILE[.//RESOURCE_TYPE/@value='IndexDSResourceType'] return distinct-values($x//BACKEND/@ID/string())";
log.debug("executing query: " + xquery);
return Sets.newHashSet(quickSearchProfile(xquery));
}
/**
* Browse.
*
* @param map
* the map
* @param backend
* the backend
* @param format
* the format
* @param layout
* the layout
* @param interpretation
* the interpretation
* @return the list< string>
* @throws IndexClientException
* the index client exception
*/
@RequestMapping(value = "/ui/index/browse.do", method = RequestMethod.POST)
@ResponseBody
public List<BrowseEntry> browse(final ModelMap map,
@RequestParam(value = "backend", required = true) final String backend,
@RequestParam(value = "format", required = true) final String format,
@RequestParam(value = "layout", required = true) final String layout,
@RequestParam(value = "interpretation", required = true) final String interpretation,
@RequestParam(value = "fields", required = true) final String fields,
@RequestParam(value = "query", required = true) final String query) throws IndexClientException {
List<String> browseFields = new Gson().fromJson(fields, new TypeToken<List<String>>() {}.getType());
if (browseFields != null) {
for (String s : browseFields) {
log.debug("Browse field " + s);
}
}
String indexClientKeys = format + "-" + layout + "-" + interpretation;
IndexClient client = null;
if (clientMap.getMap().containsKey(indexClientKeys)) {
client = clientMap.getMap().get(indexClientKeys);
} else {
client = indexClientFactory.getClient(format, layout, interpretation);
clientMap.getMap().put(indexClientKeys, client);
}
// LookupResponse result = client.lookup("*=*", null, 0, 10);
List<BrowseEntry> result = client.browse(query, browseFields, 99);
return result;
}
@RequestMapping(value = "/ui/index/delete.do", method = RequestMethod.POST)
@ResponseBody
public long delete(final ModelMap map,
@RequestParam(value = "backend", required = true) final String backend,
@RequestParam(value = "format", required = true) final String format,
@RequestParam(value = "layout", required = true) final String layout,
@RequestParam(value = "interpretation", required = true) final String interpretation,
@RequestParam(value = "query", required = true) final String query,
@RequestParam(value = "indexidentifier", required = false) final String indexId) throws IndexServiceException {
String indexClientKeys = format + "-" + layout + "-" + interpretation;
IndexClient client = null;
if (clientMap.getMap().containsKey(indexClientKeys)) {
client = clientMap.getMap().get(indexClientKeys);
} else {
client = indexClientFactory.getClient(format, layout, interpretation);
clientMap.getMap().put(indexClientKeys, client);
}
String mquery = query;
if (!StringUtils.isEmpty(indexId)) {
mquery = query + " and __dsid exact \"" + indexId + "\"";
}
return client.delete(mquery);
}
@RequestMapping(value = "/ui/index/search.do", method = RequestMethod.POST)
@ResponseBody
public LookupResponse search(final ModelMap map,
@RequestParam(value = "backend", required = true) final String backend,
@RequestParam(value = "format", required = true) final String format,
@RequestParam(value = "layout", required = true) final String layout,
@RequestParam(value = "interpretation", required = true) final String interpretation,
@RequestParam(value = "query", required = true) final String query,
@RequestParam(value = "from", required = true) final int from,
@RequestParam(value = "number", required = true) final int number,
@RequestParam(value = "indexidentifier", required = false) final String indexId
) throws IndexClientException {
String indexClientKeys = format + "-" + layout + "-" + interpretation;
log.debug(indexClientKeys);
IndexClient client = null;
if (!clientMap.getMap().containsKey(indexClientKeys)) {
clientMap.getMap().put(indexClientKeys, indexClientFactory.getClient(format, layout, interpretation));
}
client = clientMap.getMap().get(indexClientKeys);
List<String> filterId = null;
if (indexId != null && !indexId.isEmpty()) {
filterId = Lists.newArrayList("__dsid:\"" + indexId + "\"");
}
log.debug(String.format("query: '%s', filter: '%s', from: '%d', number: '%d'", query, filterId, from, number));
LookupResponse result = client.lookup(query, filterId, from, number);
ClassPathResource cpr = new ClassPathResource("/eu/dnetlib/functionality/modular/ui/xslt/gmf2document.xslt");
ApplyXslt xslt = new ApplyXslt(cpr);
List<String> convertedList = new ArrayList<String>();
for (String s : result.getRecords()) {
log.debug("response record: \n" + s);
convertedList.add(xslt.evaluate(s));
}
result.setRecords(convertedList);
return result;
}
/**
* Quick search profile.
*
* @param xquery
* the xquery
* @return the list< string>
* @throws Exception
* the exception
*/
private List<String> quickSearchProfile(final String xquery) throws Exception {
try {
return serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery);
} catch (ISLookUpException e) {
throw new Exception(e);
}
}
}

@ -0,0 +1,181 @@
package eu.dnetlib.functionality.modular.ui.index.models;
/**
* The Class IndexInfo.
*/
public class IndexInfo {
/** The Constant SEPARATOR. */
private static final String SEPARATOR = ":-:";
/** The id. */
private String id;
/** The forma. */
private String format;
/** The layout. */
private String layout;
/** The interpretation. */
private String interpretation;
/** The backend id. */
private String backendId;
private int size;
/**
* The Constructor.
*/
public IndexInfo() {
}
/**
* The Constructor.
*
* @param id
* the id
* @param forma
* the forma
* @param layout
* the layout
* @param interpretation
* the interpretation
* @param backendId
* the backend id
*/
public IndexInfo(final String id, final String forma, final String layout, final String interpretation, final String backendId) {
super();
this.id = id;
this.format = forma;
this.layout = layout;
this.interpretation = interpretation;
this.backendId = backendId;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Sets the id.
*
* @param id
* the id
*/
public void setId(final String id) {
this.id = id;
}
/**
* Gets the forma.
*
* @return the forma
*/
public String getFormat() {
return format;
}
/**
* Sets the forma.
*
* @param forma
* the forma
*/
public void setFormat(final String format) {
this.format = format;
}
/**
* Gets the layout.
*
* @return the layout
*/
public String getLayout() {
return layout;
}
/**
* Sets the layout.
*
* @param layout
* the layout
*/
public void setLayout(final String layout) {
this.layout = layout;
}
/**
* Gets the interpretation.
*
* @return the interpretation
*/
public String getInterpretation() {
return interpretation;
}
/**
* Sets the interpretation.
*
* @param interpretation
* the interpretation
*/
public void setInterpretation(final String interpretation) {
this.interpretation = interpretation;
}
/**
* Gets the backend id.
*
* @return the backend id
*/
public String getBackendId() {
return backendId;
}
/**
* Sets the backend id.
*
* @param backendId
* the backend id
*/
public void setBackendId(final String backendId) {
this.backendId = backendId;
}
public int getSize() {
return size;
}
public void setSize(final int size) {
this.size = size;
}
/**
* New instance from string. the string must have the form format:-:layout:-:interpretation:-:id:-:backendid:-:size
*
* @param serialized
* the serialized
* @return the index info
*/
public static IndexInfo newInstanceFromString(final String serialized) {
String[] values = serialized.split(SEPARATOR);
if ((values == null) || (values.length != 6)) return null;
IndexInfo tmp = new IndexInfo();
tmp.format = values[0];
tmp.layout = values[1];
tmp.interpretation = values[2];
tmp.id = values[3];
tmp.backendId = values[4];
tmp.size = Integer.parseInt(values[5]);
return tmp;
}
}

@ -0,0 +1,145 @@
package eu.dnetlib.functionality.modular.ui.index.models;
// TODO: Auto-generated Javadoc
/**
* The Class MdFormatInfo.
*/
public class MdFormatInfo {
/** The Constant SplitCharachters. */
private static final String SplitCharachters = "::";
/** The id. */
private String id;
/** The format. */
private String format;
/** The layout. */
private String layout;
/** The interpretation. */
private String interpretation;
/**
* The Constructor.
*/
public MdFormatInfo() {
}
/**
* The Constructor.
*
* @param id
* the id
* @param format
* the format
* @param layout
* the layout
* @param interpretation
* the interpretation
*/
public MdFormatInfo(final String id, final String format, final String layout, final String interpretation) {
super();
this.id = id;
this.format = format;
this.layout = layout;
this.interpretation = interpretation;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Sets the id.
*
* @param id
* the id
*/
public void setId(final String id) {
this.id = id;
}
/**
* Gets the format.
*
* @return the format
*/
public String getFormat() {
return format;
}
/**
* Sets the format.
*
* @param format
* the format
*/
public void setFormat(final String format) {
this.format = format;
}
/**
* Gets the layout.
*
* @return the layout
*/
public String getLayout() {
return layout;
}
/**
* Sets the layout.
*
* @param layout
* the layout
*/
public void setLayout(final String layout) {
this.layout = layout;
}
/**
* Gets the interpretation.
*
* @return the interpretation
*/
public String getInterpretation() {
return interpretation;
}
/**
* Sets the interpretation.
*
* @param interpretation
* the interpretation
*/
public void setInterpretation(final String interpretation) {
this.interpretation = interpretation;
}
/**
* Create a new MdFormatInfo starting from the xquery result the string MUST be in this forma $format-$layout-$interpretation::$id
*
* @param result
* the result
* @return the md format info
*/
public static MdFormatInfo initFromXqueryResult(final String result) {
String[] values = result.split(SplitCharachters);
if ((values == null) || (values.length != 2)) return null;
String[] mdref = values[0].split("-");
if ((mdref == null) || (mdref.length != 3)) return null;
return new MdFormatInfo(values[1], mdref[0], mdref[1], mdref[2]);
}
}

@ -0,0 +1,23 @@
package eu.dnetlib.functionality.modular.ui.mdstore;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class MDStoreServiceEntryPointController extends ModuleEntryPoint {
/** The lookup locator. */
@Resource
private UniqueServiceLocator serviceLocator;
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
}
}

@ -0,0 +1,318 @@
package eu.dnetlib.functionality.modular.ui.mdstore;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import eu.dnetlib.data.mdstore.DocumentNotFoundException;
import eu.dnetlib.data.mdstore.MDStoreService;
import eu.dnetlib.data.mdstore.modular.MDFormatDescription;
import eu.dnetlib.data.mdstore.modular.MDStoreUtils;
import eu.dnetlib.data.mdstore.modular.ModularMDStoreService;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory;
import eu.dnetlib.functionality.modular.ui.mdstore.model.MDStoreInfo;
import eu.dnetlib.functionality.modular.ui.mdstore.model.MDStoreResult;
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
/**
* The Class MDStoreServiceInternalController.
*/
@Controller
public class MDStoreServiceInternalController {
/**
* The Constant log.
*/
private static final Log log = LogFactory.getLog(MDStoreServiceInternalController.class);
@Value("${dnet.modular.ui.mdstore.xslt.record2document}")
private String recordXsltClasspath;
/**
* The lookup locator.
*/
@Resource
private UniqueServiceLocator serviceLocator;
@Autowired
private MDStoreUtils mdStoreUtils;
@Resource
private ResultSetClientFactory resultSetClientFactory;
@Autowired
private ModularMDStoreService mdStoreService;
private Map<String, Info> datasourceCache;
/**
* List md stores.
*
* @param map the map
* @return the list
* @throws Exception the exception
*/
@RequestMapping(value = "/ui/mdstore/listMDStores.do")
@ResponseBody
public List<MDStoreInfo> listMDStores(final ModelMap map) throws Exception {
if (datasourceCache == null) {
datasourceCache = datasourceFromMdStore();
}
final String xquery = "for $x in collection('/db/DRIVER/MDStoreDSResources/MDStoreDSResourceType') let $format := $x//METADATA_FORMAT "
+ "let $layout := $x//METADATA_FORMAT_LAYOUT let $interpretation :=$x//METADATA_FORMAT_INTERPRETATION "
+ "let $uri := $x//RESOURCE_URI/@value/string() let $id := $x//RESOURCE_IDENTIFIER/@value/string() "
+ "let $lastDate := $x//LAST_STORAGE_DATE let $size :=$x//NUMBER_OF_RECORDS "
+ "return concat($uri,'@::@',$id,'@::@',$format,'(-)',$layout, '(-)',$interpretation,'@::@',$lastDate,'@::@',$size) ";
log.debug("Executing lookup query" + xquery);
return Lists.transform(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery), input -> {
MDStoreInfo mdStoreInfo = MDStoreInfo.fromXqueryResult(input);
Info currentInfo = datasourceCache.get(mdStoreInfo.getId());
if (currentInfo != null) {
Map<String, String> datasourcesInvolved = mdStoreInfo.getDatasourcesInvolved();
if (datasourcesInvolved == null) {
datasourcesInvolved = Maps.newHashMap();
mdStoreInfo.setDatasourcesInvolved(datasourcesInvolved);
}
datasourcesInvolved.put("datasourceId", currentInfo.getDatasourceId());
datasourcesInvolved.put("datasourceName", currentInfo.getDatasourceName());
}
return mdStoreInfo;
});
}
@RequestMapping(value = "/ui/mdstore/reloadInfo")
@ResponseBody
public List<MDStoreInfo> reloadInfo(final ModelMap map) throws Exception {
datasourceCache = null;
return listMDStores(map);
}
@RequestMapping(value = "/ui/mdstore/getMdStoreInfo.do")
@ResponseBody
public MDStoreInfo getMdStoreInfo(final ModelMap map, @RequestParam(value = "id", required = true) final String profileId) throws Exception {
final MDStoreInfo mdStoreInfo = retrieveMDStoreInfo(profileId);
List<MDFormatDescription> indexFields = mdStoreUtils.getField(mdStoreInfo.getFormat(), mdStoreInfo.getLayout());
List<String> idFields;
if (indexFields != null) {
idFields = indexFields.stream().map(MDFormatDescription::getName).collect(Collectors.toList());
mdStoreInfo.setIndexFields(idFields);
}
return mdStoreInfo;
}
@RequestMapping(value = "/ui/mdstore/findRecords", method = RequestMethod.POST)
@ResponseBody
public MDStoreResult findRecords(final ModelMap map,
@RequestBody final Map<String, String> queryParam) throws Exception {
if (!queryParam.containsKey("mdId")) throw new MDStoreUIException("mdId parameters expected");
final String mdId = queryParam.get("mdId");
int offset = 0;
if (queryParam.containsKey("page")) {
try {
offset = Integer.parseInt(queryParam.get("page"));
queryParam.remove("page");
} catch (Exception e) {
log.error("Error on parsing page " + queryParam.get("page"));
}
}
queryParam.remove("mdId");
final MDStoreResult res = new MDStoreResult();
ClassPathResource cpr = new ClassPathResource(recordXsltClasspath);
ApplyXslt xslt = new ApplyXslt(cpr);
res.setResult(mdStoreService.getMDStoreRecords(mdId, 10, offset, queryParam).stream().map(xslt::evaluate).collect(Collectors.toList()));
//TERRIBLE HACK SHAME SANDRO SHAME!
int count = 0;
try {
count = Integer.parseInt(queryParam.get("count"));
} catch (Exception e) {
log.error(e);
}
res.setCount(count);
return res;
}
@RequestMapping(value = "/ui/mdstore/mdStoreResults")
@ResponseBody
public MDStoreResult getMDStoreResults(final ModelMap map,
@RequestParam(value = "mdId", required = true) final String mdId,
@RequestParam(value = "from", required = true) final int from,
@RequestParam(value = "id_query", required = false) final String idToQuery,
@RequestParam(value = "free_query", required = false) final String freeQuery) throws Exception {
MDStoreService mdService = serviceLocator.getService(MDStoreService.class, mdId);
ClassPathResource cpr = new ClassPathResource(recordXsltClasspath);
ApplyXslt xslt = new ApplyXslt(cpr);
MDStoreResult resultValues = new MDStoreResult();
resultValues.setCount(getMdStoreInfo(map, mdId).getSize());
if (idToQuery != null && !idToQuery.isEmpty()) {
try {
String record = mdService.deliverRecord(mdId, idToQuery);
resultValues.setResult(Lists.newArrayList(xslt.evaluate(record)));
return resultValues;
} catch (DocumentNotFoundException e) {
return null;
}
}
W3CEndpointReference epr = mdService.deliverMDRecords(mdId, null, null, null);
Iterable<String> result = resultSetClientFactory.getClient(epr);
List<String> convertedList = new ArrayList<>();
Iterator<String> it = result.iterator();
int currentCounter = 0;
while (currentCounter < from) {
if (it.hasNext()) {
it.next();
currentCounter++;
} else {
resultValues.setResult(convertedList);
return resultValues;
}
}
for (int i = 0; i < 10; i++) {
if (it.hasNext()) {
convertedList.add(xslt.evaluate(it.next()));
// convertedList.add(it.next());
} else {
break;
}
}
resultValues.setResult(convertedList);
return resultValues;
}
private Map<String, Info> datasourceFromMdStore() {
final String query = "for $x in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType') where $x[.//PARAM/@category/string()='MDSTORE_ID'] " +
"return concat($x//PARAM[./@name='providerId'][1]/string(), '<::>',$x//PARAM[./@name='providerName'][1]/string(), '<::>', " +
"string-join($x//PARAM[./@category/string()='MDSTORE_ID']/string(), '--'))";
final ISLookUpService lookupService = serviceLocator.getService(ISLookUpService.class);
try {
Map<String, Info> result = Maps.newHashMap();
List<String> results = lookupService.quickSearchProfile(query);
for (String item : results) {
String[] splitted = item.split("<::>");
if (splitted != null && splitted.length == 3) {
final Info currentInfo = new Info();
currentInfo.setDatasourceId(splitted[0]);
currentInfo.setDatasourceName(splitted[1]);
final String[] mdstores = splitted[2].split("--");
if (mdstores != null) {
for (String mdstore : mdstores) {
result.put(mdstore, currentInfo);
}
}
}
}
return result;
} catch (ISLookUpException e) {
log.error(e);
return null;
}
}
private MDStoreInfo retrieveMDStoreInfo(final String identifier) {
MDStoreInfo result = null;
try {
result = null;
final String xquery = " for $x in collection('/db/DRIVER/MDStoreDSResources/MDStoreDSResourceType') "
+ " where $x//RESOURCE_IDENTIFIER/@value/string()=\"%s\" return concat($x//RESOURCE_URI/@value/string() "
+ ", '@::@',$x//RESOURCE_IDENTIFIER/@value/string() ,'@::@',$x//METADATA_FORMAT,'(-)',$x//METADATA_FORMAT_LAYOUT, "
+ " '(-)', $x//METADATA_FORMAT_INTERPRETATION ,'@::@',$x//LAST_STORAGE_DATE,'@::@',$x//NUMBER_OF_RECORDS)";
List<String> results = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(String.format(xquery, identifier));
if (results != null && !results.isEmpty()) {
result = MDStoreInfo.fromXqueryResult(results.get(0));
}
} catch (ISLookUpException e) {
log.error(String.format("Error on getting information for mdstore with identifier: %s", identifier), e);
}
return result;
}
private Map<String, String> findDatasourceNameAssociatedToMdStore(final String mdStoreId) throws ISLookUpException {
final String baseQuery = "for $x in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType') where $x[.//PARAM/string()='%s'] return concat($x//PARAM[./@name='providerId'][1]/string(), '<::>',$x//PARAM[./@name='providerName'][1]/string())";
final ISLookUpService lookupService = serviceLocator.getService(ISLookUpService.class);
List<String> result = lookupService.quickSearchProfile(String.format(baseQuery, mdStoreId));
Map<String, String> datasources = Maps.newHashMap();
for (String item : result) {
String[] splitted = item.split("<::>");
if (splitted != null && splitted.length == 2) {
datasources.put(splitted[0], splitted[1]);
}
}
return datasources;
}
class Info {
private String datasourceId;
private String datasourceName;
private String mdStoreId;
public String getDatasourceName() {
return datasourceName;
}
public void setDatasourceName(String datasourceName) {
this.datasourceName = datasourceName;
}
public String getDatasourceId() {
return datasourceId;
}
public void setDatasourceId(String datasourceId) {
this.datasourceId = datasourceId;
}
public String getMdStoreId() {
return mdStoreId;
}
public void setMdStoreId(String mdStoreId) {
this.mdStoreId = mdStoreId;
}
}
}

@ -0,0 +1,20 @@
package eu.dnetlib.functionality.modular.ui.mdstore;
/**
* Created by sandro on 12/1/16.
*/
public class MDStoreUIException extends Exception {
public MDStoreUIException() {
}
public MDStoreUIException(String message) {
super(message);
}
public MDStoreUIException(Throwable e) {
super(e);
}
}

@ -0,0 +1,213 @@
package eu.dnetlib.functionality.modular.ui.mdstore.model;
import java.util.List;
import java.util.Map;
/**
* The Class MDStoreInfo.
*/
public class MDStoreInfo {
private static String DEFAULT_XQUERY_DELIMITER = "@::@";
/**
* The id.
*/
private String id;
/**
* The service uri.
*/
private String serviceURI;
/**
* The format.
*/
private String format;
/**
* The layout.
*/
private String layout;
/**
* The interpretation.
*/
private String interpretation;
/**
* The last storage data.
*/
private String lastStorageDate;
private Map<String, String> datasourcesInvolved;
private List<String> indexFields;
/**
* The size.
*/
private int size;
public static MDStoreInfo fromXqueryResult(final String result) {
MDStoreInfo info = new MDStoreInfo();
String values[] = result.split(DEFAULT_XQUERY_DELIMITER);
if (values == null || values.length != 5) {
return null;
}
info.setServiceURI(values[0]);
info.setId(values[1]);
String mdFormat[] = values[2].split("\\(-\\)");
if (mdFormat == null || mdFormat.length != 3) {
return null;
}
info.setFormat(mdFormat[0]);
info.setLayout(mdFormat[1]);
info.setInterpretation(mdFormat[2]);
info.setLastStorageDate(values[3]);
info.setSize(new Integer(values[4]));
return info;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(final String id) {
this.id = id;
}
/**
* Gets the service uri.
*
* @return the service uri
*/
public String getServiceURI() {
return serviceURI;
}
/**
* Sets the service uri.
*
* @param serviceURI the new service uri
*/
public void setServiceURI(final String serviceURI) {
this.serviceURI = serviceURI;
}
/**
* Gets the format.
*
* @return the format
*/
public String getFormat() {
return format;
}
/**
* Sets the format.
*
* @param format the new format
*/
public void setFormat(final String format) {
this.format = format;
}
/**
* Gets the layout.
*
* @return the layout
*/
public String getLayout() {
return layout;
}
/**
* Sets the layout.
*
* @param layout the new layout
*/
public void setLayout(final String layout) {
this.layout = layout;
}
/**
* Gets the interpretation.
*
* @return the interpretation
*/
public String getInterpretation() {
return interpretation;
}
/**
* Sets the interpretation.
*
* @param interpretation the new interpretation
*/
public void setInterpretation(final String interpretation) {
this.interpretation = interpretation;
}
/**
* Gets the last storage data.
*
* @return the last storage data
*/
public String getLastStorageDate() {
return lastStorageDate;
}
/**
* Sets the last storage data.
*
* @param lastStorageData the new last storage data
*/
public void setLastStorageDate(final String lastStorageDate) {
this.lastStorageDate = lastStorageDate;
}
/**
* Gets the size.
*
* @return the size
*/
public int getSize() {
return size;
}
/**
* Sets the size.
*
* @param size the new size
*/
public void setSize(final int size) {
this.size = size;
}
public Map<String, String> getDatasourcesInvolved() {
return datasourcesInvolved;
}
public void setDatasourcesInvolved(Map<String, String> datasourcesInvolved) {
this.datasourcesInvolved = datasourcesInvolved;
}
public List<String> getIndexFields() {
return indexFields;
}
public void setIndexFields(List<String> indexFields) {
this.indexFields = indexFields;
}
}

@ -0,0 +1,38 @@
package eu.dnetlib.functionality.modular.ui.mdstore.model;
import java.util.List;
/**
* Created by sandro on 12/2/16.
*/
public class MDStoreResult {
private int count;
private List<String> result;
public MDStoreResult() {
}
public MDStoreResult(int count, List<String> result) {
this.count = count;
this.result = result;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public List<String> getResult() {
return result;
}
public void setResult(List<String> result) {
this.result = result;
}
}

@ -0,0 +1,20 @@
package eu.dnetlib.functionality.modular.ui.oai;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class OaiExplorerEntryPointController extends ModuleEntryPoint {
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
if (request.getParameterMap().containsKey("oaiBaseUrl")) {
map.addAttribute("oaiBaseUrl", request.getParameter("oaiBaseUrl"));
}
}
}

@ -0,0 +1,162 @@
package eu.dnetlib.functionality.modular.ui.oai;
import com.google.common.base.Joiner;
import eu.dnetlib.functionality.modular.ui.oai.objects.OaiRequest;
import eu.dnetlib.functionality.modular.ui.oai.objects.ResponseDetails;
import eu.dnetlib.miscutils.datetime.DateUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.StringWriter;
@Controller
public class OaiExplorerInternalController {
private final static Resource oaiXslt = new ClassPathResource("/eu/dnetlib/functionality/modular/ui/xslt/oai.xslt");
private static final Log log = LogFactory.getLog(OaiExplorerInternalController.class);
@RequestMapping("/ui/oai_verb")
public @ResponseBody String oaiVerb(@RequestBody(required=true) OaiRequest req) throws Exception {
return callOaiVerb(req);
}
@RequestMapping("/ui/test_oai_verb")
public @ResponseBody ResponseDetails testOaiVerb(@RequestBody final OaiRequest req) throws Exception {
final ResponseDetails response = new ResponseDetails();
final Document doc = callOaiVerb(req, response);
if (response.isValid() && doc != null) {
final OaiRequest nextCall = new OaiRequest();
nextCall.setBaseUrl(req.getBaseUrl());
if ("Identify".equals(req.getVerb())) {
nextCall.setVerb("ListSets");
} else if ("ListSets".equals(req.getVerb())) {
nextCall.setVerb("ListMetadataFormats");
} else if ("ListMetadataFormats".equals(req.getVerb())) {
nextCall.setVerb("ListRecords");
if (doc.selectSingleNode("//*[local-name()='metadataPrefix' and text()='oai_dc']") != null) {
nextCall.setMdf("oai_dc");
} else {
nextCall.setMdf(doc.selectSingleNode("//*[local-name()='metadataPrefix']").getText());
}
} else if ("ListRecords".equals(req.getVerb())) {
nextCall.setVerb("ListIdentifiers");
nextCall.setMdf(req.getMdf());
} else if ("ListIdentifiers".equals(req.getVerb())) {
nextCall.setVerb("GetRecord");
nextCall.setMdf(req.getMdf());
nextCall.setId(doc.selectSingleNode("//*[local-name()='identifier']").getText());
} else if ("GetRecord".equals(req.getVerb())) {
// NOTHING
}
response.setNextCall(nextCall);
}
return response;
}
@RequestMapping("/ui/test_harvesting")
public @ResponseBody ResponseDetails testHarvesting(@RequestBody final OaiRequest req) throws Exception {
final ResponseDetails response = new ResponseDetails();
final Document doc = callOaiVerb(req, response);
if (response.isValid() && doc != null) {
final Node node = doc.selectSingleNode("//*[local-name() = 'resumptionToken']");
if (node != null) {
response.setSize(doc.selectNodes("//*[local-name()='" + req.getVerb() + "']/*[local-name() != 'resumptionToken']").size());
response.setCursor(NumberUtils.toInt(node.valueOf("@cursor"), -1));
response.setTotal(NumberUtils.toInt(node.valueOf("@completeListSize"), -1));
final OaiRequest nextCall = new OaiRequest();
nextCall.setBaseUrl(req.getBaseUrl());
nextCall.setVerb(req.getVerb());
nextCall.setToken(node.getText());
response.setNextCall(nextCall);
}
}
return response;
}
private String callOaiVerb(final OaiRequest req) throws Exception {
final HttpGet method = new HttpGet(!req.toQueryParams().isEmpty() ? req.getBaseUrl() + "?" + Joiner.on("&").join(req.toQueryParams()) : req.getBaseUrl());
method.addHeader("Content-type", "text/xml; charset=UTF-8");
try(CloseableHttpResponse response = HttpClients.createDefault().execute(method)) {
int responseCode = response.getStatusLine().getStatusCode();
if (HttpStatus.SC_OK != responseCode) {
log.error("Error downloading from baseUrl: " + req.getBaseUrl());
throw new RuntimeException("Error: " + responseCode);
}
final TransformerFactory tfactory = TransformerFactory.newInstance();
final Transformer transformer = tfactory.newTransformer(new StreamSource(oaiXslt.getInputStream()));
final StringWriter output = new StringWriter();
transformer.transform(new StreamSource(response.getEntity().getContent()), new StreamResult(output));
return output.toString();
}
}
private Document callOaiVerb(final OaiRequest req, final ResponseDetails details) {
final HttpGet method = new HttpGet(!req.toQueryParams().isEmpty() ? req.getBaseUrl() + "?" + Joiner.on("&").join(req.toQueryParams()) : req.getBaseUrl());
method.addHeader("Content-type", "text/xml; charset=UTF-8");
Document doc = null;
final long start = DateUtils.now();
try(CloseableHttpResponse response = HttpClients.createDefault().execute(method)) {
int responseCode = response.getStatusLine().getStatusCode();
details.setHttpCode(responseCode);
details.setValid(HttpStatus.SC_OK == responseCode);
if (HttpStatus.SC_OK == responseCode) {
try {
doc = new SAXReader().read(response.getEntity().getContent());
} catch (Exception e) {
details.setValid(false);
details.setError(e.getMessage());
}
}
} catch (Exception e) {
details.setValid(false);
details.setError(e.getMessage());
}
details.setTime(DateUtils.now() - start);
details.setVerb(req.getVerb());
return doc;
}
}

@ -0,0 +1,86 @@
package eu.dnetlib.functionality.modular.ui.oai.objects;
import com.google.common.collect.Lists;
import org.apache.http.message.BasicNameValuePair;
import java.util.List;
public class OaiRequest {
private String baseUrl;
private String verb;
private String mdf;
private String set;
private String id;
private String token;
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
public String getVerb() {
return verb;
}
public void setVerb(String verb) {
this.verb = verb;
}
public String getMdf() {
return mdf;
}
public void setMdf(String mdf) {
this.mdf = mdf;
}
public String getSet() {
return set;
}
public void setSet(String set) {
this.set = set;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public List<BasicNameValuePair> toQueryParams() {
final List<BasicNameValuePair> params = Lists.newArrayList();
if (verb != null && !verb.isEmpty()) {
params.add(new BasicNameValuePair("verb", verb));
}
if (mdf != null && !mdf.isEmpty()) {
params.add(new BasicNameValuePair("metadataPrefix", mdf));
}
if (set != null && !set.isEmpty()) {
params.add(new BasicNameValuePair("set", set));
}
if (id != null && !id.isEmpty()) {
params.add(new BasicNameValuePair("identifier", id));
}
if (token != null && !token.isEmpty()) {
params.add(new BasicNameValuePair("resumptionToken", token));
}
return params;
}
}

@ -0,0 +1,69 @@
package eu.dnetlib.functionality.modular.ui.oai.objects;
public class ResponseDetails {
private String verb;
private long time;
private int httpCode;
private boolean valid;
private String error;
private int size;
private int cursor;
private int total;
private OaiRequest nextCall;
public String getVerb() {
return verb;
}
public void setVerb(String verb) {
this.verb = verb;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public int getHttpCode() {
return httpCode;
}
public void setHttpCode(int httpCode) {
this.httpCode = httpCode;
}
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public OaiRequest getNextCall() {
return nextCall;
}
public void setNextCall(OaiRequest nextCall) {
this.nextCall = nextCall;
}
public int getCursor() {
return cursor;
}
public void setCursor(int cursor) {
this.cursor = cursor;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}

@ -0,0 +1,18 @@
/**
* Created by Sandro La Bruzzo on 11/18/15.
*/
package eu.dnetlib.functionality.modular.ui.objectStore;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
import org.springframework.ui.ModelMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ObjectStoreServiceEntryPointController extends ModuleEntryPoint {
@Override
protected void initialize(ModelMap modelMap, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
}
}

@ -0,0 +1,175 @@
package eu.dnetlib.functionality.modular.ui.objectStore;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import eu.dnetlib.data.objectstore.modular.ModularObjectStoreDeliver;
import eu.dnetlib.data.objectstore.modular.ModularObjectStoreService;
import eu.dnetlib.data.objectstore.modular.connector.ObjectStore;
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile;
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.enabling.resultset.ResultSetListener;
import eu.dnetlib.functionality.modular.ui.objectStore.info.ObjectStoreInfo;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* Created by Sandro La Bruzzo on 11/18/15.
*/
@Controller
public class ObjectStoreServiceInternalController {
private static final Log log = LogFactory.getLog(ObjectStoreServiceInternalController.class);
@Autowired
public UniqueServiceLocator serviceLocator;
@Autowired
public ModularObjectStoreService objectStoreservice;
private final Gson gson = new Gson();
private final Function<String, ObjectStoreFile> convertFunction = new Function<String, ObjectStoreFile>() {
@Override
public ObjectStoreFile apply(String input) {
return gson.fromJson(input, ObjectStoreFile.class);
}
};
@RequestMapping(value = "/ui/objectStore/listObjectStores.do")
@ResponseBody
public List<ObjectStoreInfo> listObjectStoreInfo(final ModelMap map) throws ObjectStoreServiceException {
final Map<String, ObjectStoreInfo> inputObjectStore = Maps.newHashMap();
retrieveObjectStoreFromProfiles(inputObjectStore);
retrieveObjectStoreFromService(inputObjectStore);
return Lists.newArrayList(inputObjectStore.values());
}
private void retrieveObjectStoreFromService(final Map<String, ObjectStoreInfo> inputMap) {
final List<String> stores = objectStoreservice.getFeeder().getDao().listObjectStores();
for (final String s : stores) {
if (!inputMap.containsKey(s)) {
try {
final ObjectStoreInfo info = new ObjectStoreInfo();
final ObjectStore store = objectStoreservice.getObjectStoreDeliver().getDao().getObjectStore(s);
info.setInterpretation(store.getInterpretation());
info.setSize(store.getSize());
info.setObjectStoreId(s);
info.setMissingObjectStore(false);
inputMap.put(s, info);
} catch (ObjectStoreServiceException e) {
log.error(e);
}
} else {
inputMap.get(s).setMissingObjectStore(false);
}
}
}
private void retrieveObjectStoreFromProfiles(final Map<String, ObjectStoreInfo> inputMap) {
final String query = "for $x in collection('/db/DRIVER/ObjectStoreDSResources/ObjectStoreDSResourceType') \n" +
"let $interpretation :=$x//OBJECTSTORE_INTERPRETATION\n" +
"let $uri := $x//RESOURCE_URI/@value/string() \n" +
"let $id := $x//RESOURCE_IDENTIFIER/@value/string() \n" +
"let $lastDate := $x//LAST_STORAGE_DATE \n" +
"let $size :=$x//STORE_SIZE \n" +
"return concat($uri,'@::@',$id,'@::@',$interpretation,'@::@',$lastDate,'@::@',$size) ";
ISLookUpService lookUpService = serviceLocator.getService(ISLookUpService.class);
try {
List<String> results = lookUpService.quickSearchProfile(query);
if (results == null) return;
for (String result : results) {
String dataInfo[] = result.split("@::@");
if (dataInfo != null && dataInfo.length == 5) {
final String webUri = dataInfo[0];
final String id = dataInfo[1];
final String interpretation = dataInfo[2];
final String lastDate = dataInfo[3];
final int size = Integer.parseInt(dataInfo[4]);
final ObjectStoreInfo currentInfo = new ObjectStoreInfo();
currentInfo.setObjectStoreId(id);
currentInfo.setInterpretation(interpretation);
currentInfo.setLastStorageDate(lastDate);
currentInfo.setSize(size);
currentInfo.setServiceURI(webUri);
currentInfo.setMissingProfile(false);
inputMap.put(id, currentInfo);
}
}
} catch (ISLookUpException e) {
log.error(String.format("%s", "Error on making query on is " + query, e));
}
}
@RequestMapping(value = "/ui/objectStore/getObjectStoreInfo.do")
@ResponseBody
public ObjectStoreInfo getObjectStoreInfo(
final ModelMap map, @RequestParam(value = "objId", required = true) final String objId,
@RequestParam(value = "from", required = true) final int from,
@RequestParam(value ="id",required = false) final String recordId) {
try {
final ModularObjectStoreDeliver objectStoreDeliver = objectStoreservice.getObjectStoreDeliver();
final ObjectStore store = objectStoreDeliver.getDao().getObjectStore(objId);
ResultSetListener rs;
if (recordId!=null && !StringUtils.isEmpty(recordId)){
rs = store.deliverIds(Lists.newArrayList(recordId));
}
else {
rs = store.deliver((long) 0, System.currentTimeMillis());
}
final List<String> page = rs.getResult((1 + from), (from + 25));
final ObjectStoreInfo info = new ObjectStoreInfo();
info.setInterpretation(store.getInterpretation());
info.setObjectStoreId(store.getId());
info.setSize(store.getSize());
info.setMissingObjectStore(false);
info.setMissingProfile(existId(objId));
info.setResults(Lists.transform(page, convertFunction));
return info;
} catch (ObjectStoreServiceException e) {
return null;
}
}
private boolean existId(final String objectStoreId) {
ISLookUpService lookUpService = serviceLocator.getService(ISLookUpService.class);
try {
final String resourceProfile = lookUpService.getResourceProfile(objectStoreId);
return resourceProfile == null;
} catch (ISLookUpException e) {
log.debug(objectStoreId + " not found!");
}
return true;
}
}

@ -0,0 +1,92 @@
package eu.dnetlib.functionality.modular.ui.objectStore.info;
import eu.dnetlib.data.objectstore.rmi.ObjectStoreFile;
import java.util.List;
/**
* Created by Sandro La Bruzzo on 11/19/15.
*/
public class ObjectStoreInfo {
private String objectStoreId;
private int size;
private String interpretation;
private List<ObjectStoreFile> results;
private String lastStorageDate;
private String serviceURI;
private boolean missingProfile = true;
private boolean missingObjectStore = true;
public boolean isMissingProfile() {
return missingProfile;
}
public void setMissingProfile(boolean missingProfile) {
this.missingProfile = missingProfile;
}
public boolean isMissingObjectStore() {
return missingObjectStore;
}
public void setMissingObjectStore(boolean missingObjectStore) {
this.missingObjectStore = missingObjectStore;
}
public String getLastStorageDate() {
return lastStorageDate;
}
public void setLastStorageDate(String lastStorageDate) {
this.lastStorageDate = lastStorageDate;
}
public String getServiceURI() {
return serviceURI;
}
public void setServiceURI(String serviceURI) {
this.serviceURI = serviceURI;
}
public List<ObjectStoreFile> getResults() {
return results;
}
public void setResults(List<ObjectStoreFile> results) {
this.results = results;
}
public String getObjectStoreId() {
return objectStoreId;
}
public void setObjectStoreId(String objectStoreId) {
this.objectStoreId = objectStoreId;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getInterpretation() {
return interpretation;
}
public void setInterpretation(String interpretation) {
this.interpretation = interpretation;
}
}

@ -0,0 +1,108 @@
package eu.dnetlib.functionality.modular.ui.repositories;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.ui.ModelMap;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import eu.dnetlib.data.collector.rmi.CollectorService;
import eu.dnetlib.data.collector.rmi.ProtocolDescriptor;
import eu.dnetlib.data.collector.rmi.ProtocolParameter;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
import eu.dnetlib.functionality.modular.ui.repositories.objects.VocabularyEntry;
public class AddRepoApiEntryPointController extends ModuleEntryPoint {
private String datasourceTypeVocabulary;
private String complianceVocabulary;
private String contentDescriptionsVocabulary;
private String protocolsVocabulary;
@Resource
private UniqueServiceLocator serviceLocator;
@Resource
private RepoUIUtils repoUIUtils;
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final Gson gson = new Gson();
map.addAttribute("types", gson.toJson(repoUIUtils.fetchVocabularyTerms(datasourceTypeVocabulary)));
map.addAttribute("compliances", gson.toJson(repoUIUtils.fetchVocabularyTerms(complianceVocabulary)));
map.addAttribute("contentDescriptions", gson.toJson(repoUIUtils.fetchVocabularyTerms(contentDescriptionsVocabulary)));
map.addAttribute("protocols", gson.toJson(listProtocols()));
}
private List<ProtocolDescriptor> listProtocols() throws ISLookUpException {
final Map<String, List<ProtocolParameter>> mapParams = Maps.newHashMap();
for (ProtocolDescriptor pd : serviceLocator.getService(CollectorService.class).listProtocols()) {
mapParams.put(pd.getName().trim().toLowerCase(), pd.getParams());
}
return Lists.transform(repoUIUtils.fetchVocabularyTerms(protocolsVocabulary), new Function<VocabularyEntry, ProtocolDescriptor>() {
@Override
public ProtocolDescriptor apply(final VocabularyEntry e) {
final ProtocolDescriptor pd = new ProtocolDescriptor();
pd.setName(e.getName());
if (mapParams.containsKey(e.getName().toLowerCase().trim())) {
pd.setParams(mapParams.get(e.getName().toLowerCase().trim()));
} else {
pd.setParams(new ArrayList<ProtocolParameter>());
}
return pd;
}
});
}
public String getDatasourceTypeVocabulary() {
return datasourceTypeVocabulary;
}
@Required
public void setDatasourceTypeVocabulary(final String datasourceTypeVocabulary) {
this.datasourceTypeVocabulary = datasourceTypeVocabulary;
}
public String getComplianceVocabulary() {
return complianceVocabulary;
}
@Required
public void setComplianceVocabulary(final String complianceVocabulary) {
this.complianceVocabulary = complianceVocabulary;
}
public String getContentDescriptionsVocabulary() {
return contentDescriptionsVocabulary;
}
@Required
public void setContentDescriptionsVocabulary(final String contentDescriptionsVocabulary) {
this.contentDescriptionsVocabulary = contentDescriptionsVocabulary;
}
public String getProtocolsVocabulary() {
return protocolsVocabulary;
}
@Required
public void setProtocolsVocabulary(final String protocolsVocabulary) {
this.protocolsVocabulary = protocolsVocabulary;
}
}

@ -0,0 +1,51 @@
package eu.dnetlib.functionality.modular.ui.repositories;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.ui.ModelMap;
import com.google.gson.Gson;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class AddRepoEntryPointController extends ModuleEntryPoint {
private String datasourceTypeVocabulary;
private String datasourceCountryVocabulary;
@Resource
private UniqueServiceLocator serviceLocator;
@Resource
private RepoUIUtils repoUIUtils;
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final Gson gson = new Gson();
map.addAttribute("types", gson.toJson(repoUIUtils.fetchVocabularyTerms(datasourceTypeVocabulary)));
map.addAttribute("countries", gson.toJson(repoUIUtils.fetchVocabularyTerms(datasourceCountryVocabulary)));
}
public String getDatasourceTypeVocabulary() {
return datasourceTypeVocabulary;
}
@Required
public void setDatasourceTypeVocabulary(final String datasourceTypeVocabulary) {
this.datasourceTypeVocabulary = datasourceTypeVocabulary;
}
public String getDatasourceCountryVocabulary() {
return datasourceCountryVocabulary;
}
@Required
public void setDatasourceCountryVocabulary(final String datasourceCountryVocabulary) {
this.datasourceCountryVocabulary = datasourceCountryVocabulary;
}
}

@ -0,0 +1,197 @@
package eu.dnetlib.functionality.modular.ui.repositories;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.ui.ModelMap;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import eu.dnetlib.enabling.datasources.common.Api;
import eu.dnetlib.enabling.datasources.common.Datasource;
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
import eu.dnetlib.miscutils.collections.Pair;
public class RepoApisEntryPointController extends ModuleEntryPoint {
@Resource
private UniqueServiceLocator serviceLocator;
@Resource
private RepoUIUtils repoUIUtils;
private String compatibilityLevelsVocabulary;
private String validatorAddress;
private String validatorServiceAddress;
@Autowired
private LocalDatasourceManager<Datasource<?, ?>, Api<?>> dsManager;
public class RepoHIWorkflow implements Comparable<RepoHIWorkflow> {
private final String id;
private final String name;
private final Set<String> ifaceTypes;
private final Set<String> compliances;
private List<Pair<String, String>> fields;
/**
* Instantiates a new repo hi workflow.
*
* @param id
* the id
* @param name
* the name
* @param ifaceTypes
* the iface types
* @param compliances
* the compliances
* @param fields
* the fields
*/
public RepoHIWorkflow(final String id, final String name, final Set<String> ifaceTypes, final Set<String> compliances,
final List<Pair<String, String>> fields) {
super();
this.id = id;
this.name = name;
this.ifaceTypes = ifaceTypes;
this.compliances = compliances;
this.fields = fields;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public Set<String> getIfaceTypes() {
return ifaceTypes;
}
public Set<String> getCompliances() {
return compliances;
}
@Override
public int compareTo(final RepoHIWorkflow o) {
return getName().compareTo(o.getName());
}
/**
* @return the fields
*/
public List<Pair<String, String>> getFields() {
return fields;
}
/**
* @param fields
* the fields to set
*/
public void setFields(final List<Pair<String, String>> fields) {
this.fields = fields;
}
}
private RepoHIWorkflow parseQuery(final String input) {
final SAXReader reader = new SAXReader();
try {
final Document doc = reader.read(new StringReader(input));
final String id = doc.valueOf("//id");
final String name = doc.valueOf("//name");
final String type = doc.valueOf("//types");
final String compliance = doc.valueOf("//compliances");
final Set<String> ifcTypes = Sets.newHashSet(Splitter.on(",").omitEmptyStrings().trimResults().split(type));
final Set<String> compliances = Sets.newHashSet(Splitter.on(",").omitEmptyStrings().trimResults().split(compliance));
final List<Pair<String, String>> fields = new ArrayList<>();
for (final Object o : doc.selectNodes(".//FIELD")) {
final Node currentNode = (Node) o;
final String key = currentNode.valueOf("@name");
final String value = currentNode.getText();
fields.add(new Pair<>(key, value));
}
return new RepoHIWorkflow(id, name, ifcTypes, compliances, fields);
} catch (final Exception e) {
return null;
}
}
private List<RepoHIWorkflow> listRepoHIWorkflows() throws ISLookUpException {
final String xquery =
"for $x in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType') where $x//WORKFLOW_TYPE='REPO_HI' return <result> <id>{$x//RESOURCE_IDENTIFIER/@value/string()}</id> <name>{$x//WORKFLOW_NAME/text()}</name> <types>{$x//PARAM[@name='expectedInterfaceTypologyPrefixes']/text()}</types> <compliances>{$x//PARAM[@name='expectedCompliancePrefixes']/text()}</compliances> {$x//FIELD} </result>";
final List<RepoHIWorkflow> list = Lists.newArrayList();
for (final String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) {
final RepoHIWorkflow repoHiInfo = parseQuery(s);
if (repoHiInfo != null) {
list.add(repoHiInfo);
}
}
Collections.sort(list);
return list;
}
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final Gson gson = new Gson();
map.addAttribute("availableRepohiWfs", gson.toJson(listRepoHIWorkflows()));
map.addAttribute("compatibilityLevels", gson.toJson(repoUIUtils.fetchVocabularyTerms(getCompatibilityLevelsVocabulary())));
map.addAttribute("browseFields", gson.toJson(dsManager.listBrowsableFields()));
map.addAttribute("validatorAddress", getValidatorAddress());
map.addAttribute("validatorServiceAddress", getValidatorServiceAddress());
}
public String getCompatibilityLevelsVocabulary() {
return compatibilityLevelsVocabulary;
}
@Required
public void setCompatibilityLevelsVocabulary(final String compatibilityLevelsVocabulary) {
this.compatibilityLevelsVocabulary = compatibilityLevelsVocabulary;
}
public String getValidatorAddress() {
return validatorAddress;
}
@Required
public void setValidatorAddress(final String validatorAddress) {
this.validatorAddress = validatorAddress;
}
public String getValidatorServiceAddress() {
return validatorServiceAddress;
}
@Required
public void setValidatorServiceAddress(final String validatorServiceAddress) {
this.validatorServiceAddress = validatorServiceAddress;
}
}

@ -0,0 +1,35 @@
package eu.dnetlib.functionality.modular.ui.repositories;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.ui.ModelMap;
import com.google.gson.Gson;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class RepoEnablerEntryPointController extends ModuleEntryPoint {
private String datasourceTypeVocabulary;
@Resource
private RepoUIUtils repoUIUtils;
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
map.addAttribute("types", new Gson().toJson(repoUIUtils.fetchVocabularyTerms(getDatasourceTypeVocabulary())));
}
public String getDatasourceTypeVocabulary() {
return datasourceTypeVocabulary;
}
@Required
public void setDatasourceTypeVocabulary(final String datasourceTypeVocabulary) {
this.datasourceTypeVocabulary = datasourceTypeVocabulary;
}
}

@ -0,0 +1,262 @@
package eu.dnetlib.functionality.modular.ui.repositories;
import java.io.StringReader;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import eu.dnetlib.data.collector.rmi.CollectorService;
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
import eu.dnetlib.data.collector.rmi.ProtocolParameterValue;
import eu.dnetlib.enabling.datasources.common.Api;
import eu.dnetlib.enabling.datasources.common.ApiParam;
import eu.dnetlib.enabling.datasources.common.ApiParamImpl;
import eu.dnetlib.enabling.datasources.common.BrowseTerm;
import eu.dnetlib.enabling.datasources.common.Datasource;
import eu.dnetlib.enabling.datasources.common.DsmException;
import eu.dnetlib.enabling.datasources.common.Identity;
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager;
import eu.dnetlib.enabling.datasources.common.Organization;
import eu.dnetlib.enabling.datasources.common.SearchApisEntry;
import eu.dnetlib.enabling.datasources.common.SimpleDatasource;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.error.ErrorMessage;
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoInterfaceEntry;
import eu.dnetlib.functionality.modular.ui.workflows.objects.sections.WorkflowSectionGrouper;
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
import eu.dnetlib.msro.workflows.sarasvati.loader.WorkflowExecutor;
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
@Controller
public class RepoInternalController {
@Autowired
private LocalDatasourceManager<Datasource<?, ?>, Api<?>> dsManager;
@Resource
private UniqueServiceLocator serviceLocator;
@Resource
private WorkflowSectionGrouper workflowSectionGrouper;
@Resource
private WorkflowExecutor workflowExecutor;
@Resource
private RepoUIUtils repoUIUtils;
private static final Log log = LogFactory.getLog(RepoInternalController.class);
@RequestMapping(value = "/ui/browseRepoField.do")
public @ResponseBody List<? extends BrowseTerm> browseRepoField(@RequestParam(value = "field", required = true) final String field) throws Exception {
return dsManager.browseField(field);
}
@Cacheable(cacheNames = "repoUIJsonCache", key = "#param, #value", condition = "#refresh == false")
@RequestMapping(value = "/ui/listApis.do")
public @ResponseBody List<? extends SearchApisEntry> listApis(
@RequestParam(value = "param", required = true) final String param,
@RequestParam(value = "value", required = true) final String value,
@RequestParam(value = "refresh", required = false) final String refresh) throws Exception {
return dsManager.searchApis(param, value);
}
@RequestMapping(value = "/ui/listRepositories.json")
public @ResponseBody List<SimpleDatasource> listRepositories(@RequestParam(value = "type", required = true) final String type) throws Exception {
return dsManager.searchDatasourcesByType(type);
}
@CacheEvict("repoUIJsonCache")
@RequestMapping(value = "/ui/validateRepo.do")
public @ResponseBody String listRepositories(@RequestParam(value = "id", required = true) final String id,
@RequestParam(value = "b", required = true) final boolean b) throws Exception {
final String query = "count(/*[.//RESOURCE_TYPE/@value='MetaWorkflowDSResourceType' and .//DATAPROVIDER/@id='" + id + "'])";
if (!b && Integer.parseInt(serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query)) > 0) { throw new Exception("Repo " + id
+ " can be invalidated: it is related to some metawfs"); }
final String newId = b ? serviceLocator.getService(ISRegistryService.class).validateProfile(id)
: serviceLocator.getService(ISRegistryService.class).invalidateProfile(id);
return newId;
}
@RequestMapping(value = "/ui/getRepoDetails.do")
public void getRepoDetails(final HttpServletResponse response, @RequestParam(value = "id", required = true) final String id) throws Exception {
String profile;
try {
profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(id);
} catch (final ISLookUpDocumentNotFoundException e) {
profile = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(
"collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')/*[.//DATASOURCE_ORIGINAL_ID='" + id + "']");
}
final ApplyXslt xslt = new ApplyXslt(IOUtils.toString(getClass().getResourceAsStream(
"/eu/dnetlib/functionality/modular/ui/repositories/xslt/repoDetails.xslt")));
IOUtils.copy(new StringReader(xslt.evaluate(profile)), response.getOutputStream());
}
@RequestMapping("/ui/repoMetaWf.new")
public @ResponseBody String newDataProviderWorkflow(@RequestParam(value = "id", required = true) final String repoId,
@RequestParam(value = "name", required = true) final String repoName,
@RequestParam(value = "iface", required = true) final String ifaceId,
@RequestParam(value = "wf", required = true) final String wfId) throws Exception {
final Map<String, Object> params = Maps.newHashMap();
params.put(WorkflowsConstants.DATAPROVIDER_ID, repoId);
params.put(WorkflowsConstants.DATAPROVIDER_NAME, repoName);
params.put(WorkflowsConstants.DATAPROVIDER_INTERFACE, ifaceId);
return workflowExecutor.startProcess(wfId, params);
}
@RequestMapping("/ui/repoMetaWf.destroy")
public @ResponseBody String destroyDataProviderWorkflow(@RequestParam(value = "destroyWf", required = true) final String destroyWfId)
throws Exception {
return workflowExecutor.startProcess(destroyWfId, null);
}
@RequestMapping("/ui/repoApi.get")
public @ResponseBody RepoInterfaceEntry getRepoApi(@RequestParam(value = "repoId", required = true) final String repoId,
@RequestParam(value = "ifaceId", required = true) final String ifaceId) throws Exception {
try {
return repoUIUtils.getApi(repoId, ifaceId);
} catch (ISLookUpDocumentNotFoundException e) {
log.warn(String.format("the Interface '%s' is not available for repository '%s', try to sync DB and profiles via the DatasourceManager", ifaceId, repoId));
dsManager.setActive(repoId, ifaceId, dsManager.isActive(repoId, ifaceId));
return repoUIUtils.getApi(repoId, ifaceId);
}
}
@RequestMapping("/ui/repoApi.update")
public @ResponseBody boolean updateRepoApi(
@RequestParam(value = "id", required = true) final String repoId,
@RequestParam(value = "iface", required = true) final String ifaceId,
@RequestParam(value = "accessParams", required = false) final String accessParamsJson,
@RequestParam(value = "mdIdPath", required = false) final String mdIdPath) throws Exception {
if (!StringUtils.isEmpty(accessParamsJson)) {
final Map<String, String> params = new Gson().fromJson(accessParamsJson, new TypeToken<Map<String, String>>() {}.getType());
final String baseUrl = params.remove("baseUrl");
dsManager.updateApiDetails(repoId, ifaceId, mdIdPath, baseUrl, params);
}
return true;
}
@RequestMapping("/ui/repoApi.delete")
public @ResponseBody boolean updateRepoApi(
@RequestParam(value = "repo", required = true) final String repoId,
@RequestParam(value = "iface", required = true) final String ifaceId) throws Exception {
dsManager.deleteApi(repoId, ifaceId);
return true;
}
@CacheEvict("repoUIJsonCache")
@RequestMapping("/ui/repoApiCompliance.update")
public @ResponseBody boolean updateRepoApiCompliance(@RequestParam(value = "id", required = true) final String repoId,
@RequestParam(value = "iface", required = true) final String ifaceId,
@RequestParam(value = "compliance", required = true) final String compliance) throws Exception {
log.debug("SET COMPLIANCE TO " + compliance);
dsManager.updateCompliance(repoId, ifaceId, compliance, true);
return true;
}
@CacheEvict("repoUIJsonCache")
@RequestMapping("/ui/repoApiCompliance.reset")
public @ResponseBody boolean resetRepoApiCompliance(@RequestParam(value = "id", required = true) final String repoId,
@RequestParam(value = "iface", required = true) final String ifaceId) throws Exception {
log.debug("RESET COMPLIANCE");
dsManager.updateCompliance(repoId, ifaceId, null, true);
return true;
}
@RequestMapping("/ui/repos/repoApi.html")
public void resetRepoApiCompliance(final ModelMap map) throws Exception {}
@RequestMapping("/ui/repoApi.new")
public @ResponseBody boolean addRepoApi(@RequestParam(value = "repoId", required = true) final String repoId,
@RequestParam(value = "iface", required = true) final String ifaceJson) throws DsmException {
final Api<ApiParam> iface = new Gson().fromJson(ifaceJson, new TypeToken<Api<ApiParamImpl>>() {}.getType());
iface.setDatasource(repoId);
log.info("Adding api " + iface.getId() + " to repository " + repoId);
dsManager.addApi(iface);
return true;
}
@RequestMapping("/ui/repo.new")
public @ResponseBody boolean addRepoApi(@RequestParam(value = "repo", required = true) final String repoJson) throws DsmException {
final Datasource<Organization<?>, Identity> ds = new Gson().fromJson(repoJson, new TypeToken<Datasource<Organization<?>, Identity>>() {}.getType());
final Date now = new Date();
ds.setDateofcollection(new java.sql.Date(now.getTime()));
if (StringUtils.isBlank(ds.getEnglishname())) {
ds.setEnglishname(ds.getOfficialname());
}
log.info("Adding datasource " + ds.getId() + " - name " + ds.getOfficialname());
dsManager.saveDs(ds);
return true;
}
@RequestMapping("/ui/listValidValuesForParam.do")
public @ResponseBody List<ProtocolParameterValue> listValidValuesForParam(
@RequestParam(value = "protocol", required = true) final String protocol,
@RequestParam(value = "param", required = true) final String param,
@RequestParam(value = "baseUrl", required = true) final String baseUrl) throws CollectorServiceException {
return serviceLocator.getService(CollectorService.class).listValidValuesForParam(protocol, baseUrl, param, null);
}
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public @ResponseBody ErrorMessage handleException(final HttpServletRequest req, final Exception e) {
log.error("Error processing " + req.getRequestURI(), e);
return new ErrorMessage(e.getMessage(), ExceptionUtils.getStackTrace(e));
}
}

@ -0,0 +1,204 @@
package eu.dnetlib.functionality.modular.ui.repositories;
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.antlr.stringtemplate.StringTemplate;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.springframework.core.io.ClassPathResource;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import eu.dnetlib.data.collector.rmi.CollectorService;
import eu.dnetlib.data.collector.rmi.ProtocolDescriptor;
import eu.dnetlib.data.collector.rmi.ProtocolParameter;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoInterfaceEntry;
import eu.dnetlib.functionality.modular.ui.repositories.objects.RepoMetaWfEntry;
import eu.dnetlib.functionality.modular.ui.repositories.objects.SimpleParamEntry;
import eu.dnetlib.functionality.modular.ui.repositories.objects.VocabularyEntry;
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
public class RepoUIUtils {
@Resource
private UniqueServiceLocator serviceLocator;
private final ClassPathResource getRepoApiQueryTmpl =
new ClassPathResource("/eu/dnetlib/functionality/modular/ui/repositories/templates/getRepoApi.xquery.st");
private static final Log log = LogFactory.getLog(RepoUIUtils.class);
private final Map<String, List<ProtocolParameter>> parametersMap = Maps.newHashMap();
public RepoInterfaceEntry getApi(final String repoId, final String ifaceId) throws Exception {
final RepoInterfaceEntry ifc = new RepoInterfaceEntry();
final StringTemplate st = new StringTemplate(IOUtils.toString(getRepoApiQueryTmpl.getInputStream()));
st.setAttribute("dsId", repoId);
st.setAttribute("ifaceId", ifaceId);
final String query = st.toString();
final SAXReader reader = new SAXReader();
final String s = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query);
final Document doc = reader.read(new StringReader(s));
ifc.setId(doc.valueOf("/api/id"));
ifc.setLabel(doc.valueOf("/api/label"));
ifc.setRemovable(doc.valueOf("/api/removable").equalsIgnoreCase("true") && doc.selectNodes("//metaWF").isEmpty());
ifc.setRepoId(doc.valueOf("/api/repo/@id"));
ifc.setRepoName(StringEscapeUtils.unescapeHtml(doc.valueOf("/api/repo")));
ifc.setRepoCountry(doc.valueOf("/api/repo/@country"));
ifc.setRepoPrefix(doc.valueOf("/api/repo/@prefix"));
ifc.setRepoType(doc.valueOf("/api/repo/@type"));
ifc.setEmail(doc.valueOf("/api/repo/@email"));
final String protocol = doc.valueOf("/api/protocol");
ifc.setProtocol(protocol);
final Set<String> toVerifyParams = getParameterNamesForProtocol(ifc.getProtocol());
for (final Object o : doc.selectNodes("/api/commonParams/param")) {
final Node n = (Node) o;
ifc.getCommonParams().add(new SimpleParamEntry(n.valueOf("@name"), n.getText()));
}
log.debug("****** " + toVerifyParams);
for (final Object o : doc.selectNodes("/api/accessParams/param")) {
final Node n = (Node) o;
final String pname = n.valueOf("@name");
if (toVerifyParams.contains(pname)) {
ifc.getAccessParams().add(new SimpleParamEntry(pname, n.getText()));
toVerifyParams.remove(pname);
} else {
log.warn("Invalid param [" + pname + "] for protocol " + protocol + " in repo " + repoId);
}
}
for (final String pname : toVerifyParams) {
ifc.getAccessParams().add(new SimpleParamEntry(pname, ""));
log.info("Adding missing param [" + pname + "] for protocol " + protocol + " in repo " + repoId);
}
for (final Object o : doc.selectNodes("/api/extraFields/field")) {
final Node n = (Node) o;
final String name = n.valueOf("@name");
final String value = n.getText();
if (name.equalsIgnoreCase("overriding_compliance")) {
for (final SimpleParamEntry e : ifc.getCommonParams()) {
if (e.getName().equals("compliance")) {
// The original compliance (assigned by the validator) is stored in otherValue
e.setOtherValue(value);
}
}
} else if (name.equalsIgnoreCase("last_aggregation_date")) {
ifc.setAggrDate(value);
} else if (name.equalsIgnoreCase("last_aggregation_total")) {
ifc.setAggrTotal(NumberUtils.toInt(value, 0));
} else if (name.equalsIgnoreCase("last_aggregation_mdId")) {
ifc.setAggrMdId(value);
} else if (name.equalsIgnoreCase("last_collection_date")) {
ifc.setCollDate(value);
} else if (name.equalsIgnoreCase("last_collection_total")) {
ifc.setCollTotal(NumberUtils.toInt(value, 0));
} else if (name.equalsIgnoreCase("last_collection_mdId")) {
ifc.setCollMdId(value);
} else if (name.equalsIgnoreCase("last_download_date")) {
ifc.setDownloadDate(value);
} else if (name.equalsIgnoreCase("last_download_total")) {
ifc.setDownloadTotal(NumberUtils.toInt(value, 0));
} else if (name.equalsIgnoreCase("last_download_objId")) {
ifc.setDownloadObjId(value);
} else {
ifc.getOtherParams().add(new SimpleParamEntry(name, value));
}
}
if (doc.selectNodes("/api/extraFields/field[@name='metadata_identifier_path']").isEmpty()) {
ifc.getOtherParams().add(new SimpleParamEntry("metadata_identifier_path", ""));
}
for (final Object o : doc.selectNodes("//metaWF")) {
final Node n = (Node) o;
final String id = n.valueOf("./id");
final String name = n.valueOf("./name");
final String status = n.valueOf("./status");
final String repoByeWfId = n.valueOf("./destroyWorkflow");
int progress = 0;
try {
switch (WorkflowStatus.valueOf(status)) {
case MISSING:
progress = 0;
break;
case ASSIGNED:
progress = 25;
break;
case WAIT_SYS_SETTINGS:
progress = 50;
break;
case WAIT_USER_SETTINGS:
progress = 75;
break;
case EXECUTABLE:
progress = 100;
break;
}
} catch (final Exception e) {
progress = 0;
}
ifc.getMetaWFs().add(new RepoMetaWfEntry(id, name, status, repoByeWfId, progress));
}
return ifc;
}
public List<VocabularyEntry> fetchVocabularyTerms(final String voc) throws ISLookUpException {
final String xquery = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code = '"
+ voc.trim() + "']//TERM return concat($x/@code, ' @@@ ', $x/@english_name)";
final List<VocabularyEntry> list = Lists.newArrayList();
for (final String s : serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery)) {
final String[] arr = s.split("@@@");
list.add(new VocabularyEntry(arr[0].trim(), arr[1].trim()));
}
Collections.sort(list);
return list;
}
private Set<String> getParameterNamesForProtocol(final String protocol) {
if (parametersMap.isEmpty()) {
for (final ProtocolDescriptor d : serviceLocator.getService(CollectorService.class).listProtocols()) {
parametersMap.put(d.getName().toLowerCase(), d.getParams());
}
}
final Set<String> res = Sets.newHashSet();
if (parametersMap.containsKey(protocol.toLowerCase())) {
res.add("baseUrl");
for (final ProtocolParameter p : parametersMap.get(protocol.toLowerCase())) {
res.add(p.getName());
}
}
return res;
}
}

@ -0,0 +1,16 @@
package eu.dnetlib.functionality.modular.ui.repositories;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
@Deprecated
public class RepositoriesGoogleMapEntryPointController extends ModuleEntryPoint {
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {}
}

@ -0,0 +1,146 @@
package eu.dnetlib.functionality.modular.ui.repositories.objects;
import java.util.ArrayList;
import java.util.List;
import eu.dnetlib.enabling.datasources.common.SearchApisEntry;
public class RepoInterfaceEntry extends SearchApisEntry {
private String label;
private boolean removable = false;
private String collDate = "";
private int collTotal = 0;
private String collMdId = "";
private String aggrMdId = "";
private String downloadDate = "";
private int downloadTotal = 0;
private String downloadObjId = "";
private String repoType;
private String email;
private List<SimpleParamEntry> commonParams = new ArrayList<>();
private List<SimpleParamEntry> accessParams = new ArrayList<>();
private List<SimpleParamEntry> otherParams = new ArrayList<>();
private List<RepoMetaWfEntry> metaWFs = new ArrayList<>();
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
public String getCollDate() {
return collDate;
}
public void setCollDate(final String collDate) {
this.collDate = collDate;
}
public int getCollTotal() {
return collTotal;
}
public void setCollTotal(final int collTotal) {
this.collTotal = collTotal;
}
public List<SimpleParamEntry> getCommonParams() {
return commonParams;
}
public void setCommonParams(final List<SimpleParamEntry> commonParams) {
this.commonParams = commonParams;
}
public List<SimpleParamEntry> getAccessParams() {
return accessParams;
}
public void setAccessParams(final List<SimpleParamEntry> accessParams) {
this.accessParams = accessParams;
}
public List<SimpleParamEntry> getOtherParams() {
return otherParams;
}
public void setOtherParams(final List<SimpleParamEntry> otherParams) {
this.otherParams = otherParams;
}
public List<RepoMetaWfEntry> getMetaWFs() {
return metaWFs;
}
public void setMetaWFs(final List<RepoMetaWfEntry> metaWFs) {
this.metaWFs = metaWFs;
}
public String getAggrMdId() {
return aggrMdId;
}
public void setAggrMdId(final String aggrMdId) {
this.aggrMdId = aggrMdId;
}
public String getCollMdId() {
return collMdId;
}
public void setCollMdId(final String collMdId) {
this.collMdId = collMdId;
}
public String getDownloadDate() {
return downloadDate;
}
public void setDownloadDate(final String downloadDate) {
this.downloadDate = downloadDate;
}
public int getDownloadTotal() {
return downloadTotal;
}
public void setDownloadTotal(final int downloadTotal) {
this.downloadTotal = downloadTotal;
}
public String getDownloadObjId() {
return downloadObjId;
}
public void setDownloadObjId(final String downloadObjId) {
this.downloadObjId = downloadObjId;
}
public String getRepoType() {
return repoType;
}
public void setRepoType(final String repoType) {
this.repoType = repoType;
}
public String getEmail() {
return email;
}
public void setEmail(final String email) {
this.email = email;
}
public boolean isRemovable() {
return removable;
}
public void setRemovable(final boolean removable) {
this.removable = removable;
}
}

@ -0,0 +1,44 @@
package eu.dnetlib.functionality.modular.ui.repositories.objects;
public class RepoMetaWfEntry implements Comparable<RepoMetaWfEntry> {
private String id;
private String name;
private String status;
private String destroyWorkflow;
private int progress;
public RepoMetaWfEntry(final String id, final String name, final String status, final String destroyWorkflow, final int progress) {
this.id = id;
this.name = name;
this.status = status;
this.destroyWorkflow = destroyWorkflow;
this.progress = progress;
}
@Override
public int compareTo(final RepoMetaWfEntry o) {
return getName().compareTo(o.getName());
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getStatus() {
return status;
}
public String getDestroyWorkflow() {
return destroyWorkflow;
}
public int getProgress() {
return progress;
}
}

@ -0,0 +1,62 @@
package eu.dnetlib.functionality.modular.ui.repositories.objects;
public class SimpleParamEntry implements Comparable<SimpleParamEntry> {
private String id;
private String name;
private Object value;
private Object otherValue;
public SimpleParamEntry(final String name, final Object value) {
this(name, name, value, null);
}
public SimpleParamEntry(final String id, final String name, final Object value) {
this(id, name, value, null);
}
public SimpleParamEntry(final String id, final String name, final Object value, final Object otherValue) {
this.id = id;
this.name = name;
this.value = value;
this.setOtherValue(otherValue);
}
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public Object getValue() {
return value;
}
public void setValue(final Object value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public Object getOtherValue() {
return otherValue;
}
public void setOtherValue(Object otherValue) {
this.otherValue = otherValue;
}
@Override
public int compareTo(final SimpleParamEntry o) {
return getName().compareTo(o.getName());
}
}

@ -0,0 +1,36 @@
package eu.dnetlib.functionality.modular.ui.repositories.objects;
public class VocabularyEntry implements Comparable<VocabularyEntry> {
private String name;
private String desc;
public VocabularyEntry() {}
public VocabularyEntry(final String name, final String desc) {
this.name = name;
this.desc = desc;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(final String desc) {
this.desc = desc;
}
@Override
public int compareTo(final VocabularyEntry o) {
return getName().compareTo(o.getName());
}
}

@ -0,0 +1,7 @@
package eu.dnetlib.functionality.modular.ui.users;
import java.util.Set;
public interface AccessLimited {
public Set<PermissionLevel> getPermissionLevels();
}

@ -0,0 +1,10 @@
package eu.dnetlib.functionality.modular.ui.users;
import java.util.Map;
import java.util.Set;
public interface AuthorizationDAO {
void updatePermissionLevels(Map<String, Set<PermissionLevel>> map);
Map<String, Set<PermissionLevel>> getPermissionLevels();
Set<PermissionLevel> getPermissionLevels(String uid);
}

@ -0,0 +1,7 @@
package eu.dnetlib.functionality.modular.ui.users;
import javax.servlet.http.HttpServletRequest;
public interface AuthorizationManager {
User obtainUserDetails(HttpServletRequest request);
}

@ -0,0 +1,20 @@
package eu.dnetlib.functionality.modular.ui.users;
import javax.servlet.http.HttpServletRequest;
import com.google.common.collect.Sets;
public class MockAuthorizationManager implements AuthorizationManager {
@Override
public User obtainUserDetails(HttpServletRequest request) {
final User userMock = new User();
userMock.setId("mock");
userMock.setFullname("Mock User");
userMock.setPermissionLevels(Sets.newHashSet(PermissionLevel.SUPER_ADMIN));
userMock.setEmail("mock@user.foo");
return userMock;
}
}

@ -0,0 +1,102 @@
package eu.dnetlib.functionality.modular.ui.users;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Required;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
public class MongoAuthorizationDAO implements AuthorizationDAO {
private DB db;
private static final String AUTH_COLL = "users";
private static final Log log = LogFactory.getLog(MongoAuthorizationDAO.class);
@Override
public void updatePermissionLevels(Map<String, Set<PermissionLevel>> map) {
final DBCollection coll = db.getCollection(AUTH_COLL);
final List<DBObject> list = Lists.newArrayList();
for (Entry<String, Set<PermissionLevel>> e : map.entrySet()) {
final Map<String, String> m = Maps.newHashMap();
m.put("uid" , e.getKey());
m.put("levels", serializeLevels(e.getValue()));
list.add(BasicDBObjectBuilder.start(m).get());
}
coll.remove(new BasicDBObject());
coll.insert(list);
}
@Override
public Map<String, Set<PermissionLevel>> getPermissionLevels() {
final DBCollection coll = db.getCollection(AUTH_COLL);
final DBCursor cur = coll.find();
final Map<String, Set<PermissionLevel>> res = Maps.newHashMap();
while (cur.hasNext()) {
final DBObject o = cur.next();
res.put((String) o.get("uid"), readLevels(o));
}
return res;
}
@Override
public Set<PermissionLevel> getPermissionLevels(String uid) {
final DBCollection coll = db.getCollection(AUTH_COLL);
final DBObject obj = coll.findOne(new BasicDBObject("uid", uid));
return readLevels(obj);
}
private Set<PermissionLevel> readLevels(final DBObject obj) {
final Set<PermissionLevel> set = new HashSet<PermissionLevel>();
if (obj != null) {
final Object levels = obj.get("levels");
if (levels != null) {
for (String s : Splitter.on(",").omitEmptyStrings().trimResults().split(levels.toString())) {
try {
set.add(PermissionLevel.valueOf(s));
} catch (Throwable e) {
log.error("Invalid permissionLevel: " + s);
}
}
}
}
return set;
}
private String serializeLevels(Set<PermissionLevel> levels) {
return Joiner.on(",").skipNulls().join(levels);
}
public DB getDb() {
return db;
}
@Required
public void setDb(DB db) {
this.db = db;
}
}

@ -0,0 +1,28 @@
package eu.dnetlib.functionality.modular.ui.users;
public enum PermissionLevel {
SUPER_ADMIN("Super admin", "Authenticated user with ALL management rights"),
DS_ADMIN ("datasource administrator", "Authenticated user that can manage datasources"),
WF_ADMIN("workflow administrator", "Authenticated user that can manage workflows"),
IS_ADMIN("information administrator", "Authenticated user that can update IS profiles"),
USER("simple user", "Authenticated user with no management rights"),
GUEST ("guest", "Anonymous user");
private String label;
private String details;
private PermissionLevel(final String label, final String details) {
this.label = label;
this.details = details;
}
public String getLabel() {
return label;
}
public String getDetails() {
return details;
}
}

@ -0,0 +1,61 @@
package eu.dnetlib.functionality.modular.ui.users;
import java.security.Principal;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Required;
import com.google.common.collect.Sets;
public class SimpleAuthorizationManager implements AuthorizationManager {
private AuthorizationDAO authorizationDAO;
private String defaultSuperAdmin;
@Override
public User obtainUserDetails(final HttpServletRequest request) {
final Principal principal = request.getUserPrincipal();
final User user = new User();
if (principal != null) {
final String username = principal.getName();
if (username != null) {
user.setId(username);
user.setFullname(username);
user.setPermissionLevels(authorizationDAO.getPermissionLevels(username));
if (username.equals(getDefaultSuperAdmin())) {
user.getPermissionLevels().add(PermissionLevel.SUPER_ADMIN);
}
} else {
user.setId("anonymous");
user.setFullname("anonymous");
user.setPermissionLevels(Sets.newHashSet(PermissionLevel.GUEST));
}
}
return user;
}
public AuthorizationDAO getAuthorizationDAO() {
return authorizationDAO;
}
@Required
public void setAuthorizationDAO(AuthorizationDAO authorizationDAO) {
this.authorizationDAO = authorizationDAO;
}
public String getDefaultSuperAdmin() {
return defaultSuperAdmin;
}
@Required
public void setDefaultSuperAdmin(String defaultSuperAdmin) {
this.defaultSuperAdmin = defaultSuperAdmin;
}
}

@ -0,0 +1,163 @@
package eu.dnetlib.functionality.modular.ui.users;
import java.net.URLDecoder;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.KeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import com.google.gson.Gson;
public class SimpleSSOAuthorizationManager implements AuthorizationManager {
private static final Log log = LogFactory.getLog(SimpleSSOAuthorizationManager.class);
private Resource pubKeyFile = new ClassPathResource("/eu/dnetlib/functionality/modular/ui/users/pubkey.der");
private String pubKeyAlgo = "RSA";
private String signatureAlgo = "SHA1withRSA";
private PublicKey publicKey;
private AuthorizationDAO authorizationDAO;
private String defaultSuperAdmin;
@Override
public User obtainUserDetails(final HttpServletRequest request) {
if (request.getCookies() != null) {
for (Cookie cookie : request.getCookies()) {
if (cookie.getName().equalsIgnoreCase("rinfra-user")) {
try {
return processCookie(cookie.getValue());
} catch (Exception e) {
log.error("Error processing cookie: " + cookie.getValue(), e);
return null;
}
}
}
}
return null;
}
private User processCookie(final String s) throws Exception {
if (s == null || s.isEmpty()) {
return null;
}
final Gson gson = new Gson();
final Map<?,?> map = gson.fromJson(new String(Base64.decodeBase64(URLDecoder.decode(s.trim(), "UTF-8"))), Map.class);
final String message = (String) map.get("payload");
final String signature = (String) map.get("signature");
if (isValidMessage(message, signature)) {
final Map<?,?> userMap = gson.fromJson(message, Map.class);
if (userMap.containsKey("uid")) {
final String uid = (String) userMap.get("uid");
final User user = new User(uid);
user.setEmail((String) userMap.get("email"));
user.setFullname(userMap.containsKey("fullname") ? (String) userMap.get("fullname") : uid);
user.setPermissionLevels(authorizationDAO.getPermissionLevels(uid));
if (isDefaultSuperAdmin(uid)) {
user.getPermissionLevels().add(PermissionLevel.SUPER_ADMIN);
}
return user;
}
}
return null;
}
private boolean isDefaultSuperAdmin(final String uid) {
return (uid != null && !uid.isEmpty() && uid.equals(getDefaultSuperAdmin()));
}
protected boolean isValidMessage(final String message, final String signature) {
log.info("checking message " + message + " with sig " + signature);
if (message == null || message.isEmpty() || signature == null || signature.isEmpty()) {
log.error("Null or empty values in message or signature");
return false;
}
try {
final Signature sg = Signature.getInstance(getSignatureAlgo());
sg.initVerify(getPublicKey());
sg.update(message.getBytes());
return sg.verify(Hex.decodeHex(signature.toCharArray()));
} catch(Exception e) {
log.error("Error verifyng signature", e);
return false;
}
}
public void init() throws Exception {
final byte[] keyBytes = IOUtils.toByteArray(getPubKeyFile().getInputStream());
final KeySpec spec = new X509EncodedKeySpec(keyBytes);
setPublicKey(KeyFactory.getInstance(getPubKeyAlgo()).generatePublic(spec));
}
public Resource getPubKeyFile() {
return pubKeyFile;
}
@Required
public void setPubKeyFile(Resource pubKeyFile) {
this.pubKeyFile = pubKeyFile;
}
public String getPubKeyAlgo() {
return pubKeyAlgo;
}
@Required
public void setPubKeyAlgo(String pubKeyAlgo) {
this.pubKeyAlgo = pubKeyAlgo;
}
public String getSignatureAlgo() {
return signatureAlgo;
}
@Required
public void setSignatureAlgo(String signatureAlgo) {
this.signatureAlgo = signatureAlgo;
}
public PublicKey getPublicKey() {
return publicKey;
}
public void setPublicKey(PublicKey publicKey) {
this.publicKey = publicKey;
}
public AuthorizationDAO getAuthorizationDAO() {
return authorizationDAO;
}
@Required
public void setAuthorizationDAO(AuthorizationDAO authorizationDAO) {
this.authorizationDAO = authorizationDAO;
}
public String getDefaultSuperAdmin() {
return defaultSuperAdmin;
}
@Required
public void setDefaultSuperAdmin(String defaultSuperAdmin) {
this.defaultSuperAdmin = defaultSuperAdmin;
}
}

@ -0,0 +1,48 @@
package eu.dnetlib.functionality.modular.ui.users;
import java.util.Set;
public class User implements Comparable<User> {
private String id;
private String fullname;
private String email;
private Set<PermissionLevel> permissionLevels;
public User() {}
public User(final String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Set<PermissionLevel> getPermissionLevels() {
return permissionLevels;
}
public void setPermissionLevels(Set<PermissionLevel> permissionLevels) {
this.permissionLevels = permissionLevels;
}
@Override
public int compareTo(final User o) {
return getId().compareTo(o.getId());
}
}

@ -0,0 +1,69 @@
package eu.dnetlib.functionality.modular.ui.utils;
public class LogLine {
private long id;
private String level;
private String name;
private String date;
private String message;
private String stacktrace;
public LogLine(final long id, final String level, final String name, final String date, final String message, final String stacktrace) {
this.id = id;
this.level = level;
this.name = name;
this.date = date;
this.message = message;
this.stacktrace = stacktrace;
}
public final long getId() {
return id;
}
public final void setId(final long id) {
this.id = id;
}
public final String getLevel() {
return level;
}
public final void setLevel(final String level) {
this.level = level;
}
public final String getName() {
return name;
}
public final void setName(final String name) {
this.name = name;
}
public final String getDate() {
return date;
}
public final void setDate(final String date) {
this.date = date;
}
public final String getMessage() {
return message;
}
public final void setMessage(final String message) {
this.message = message;
}
public final String getStacktrace() {
return stacktrace;
}
public final void setStacktrace(final String stacktrace) {
this.stacktrace = stacktrace;
}
}

@ -0,0 +1,80 @@
package eu.dnetlib.functionality.modular.ui.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
public class LogUiAppender extends AppenderSkeleton {
public static final int MAX_LOGS_IN_QUEUE = 2000;
private final LinkedBlockingQueue<LogLine> logQueue = Queues.newLinkedBlockingQueue(MAX_LOGS_IN_QUEUE);
private int count = 0;
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
protected void append(final LoggingEvent event) {
synchronized (logQueue) {
if (logQueue.remainingCapacity() == 0) {
logQueue.poll();
}
try {
final String date = dateFormat.format(new Date(event.getTimeStamp()));
final String[] arr = event.getThrowableStrRep();
final String strace = arr != null && arr.length > 0 ? Joiner.on("\n").join(arr) : "";
logQueue.put(new LogLine(count++, event.getLevel().toString(), event.getLoggerName(), date, event.getRenderedMessage(), strace));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
public List<LogLine> tail_N(final int n) throws Exception {
synchronized (logQueue) {
int qSize = logQueue.size();
if (n <= 0 || qSize == 0) {
return Lists.newArrayList();
} else if (n < qSize) {
return Lists.newArrayList(logQueue).subList(qSize - n, qSize);
} else {
return Lists.newArrayList(logQueue);
}
}
}
public List<LogLine> tail_continue(final int after) throws Exception {
synchronized (logQueue) {
return Lists.newArrayList(Iterables.filter(logQueue, new Predicate<LogLine>() {
@Override
public boolean apply(final LogLine ll) {
return ll.getId() > after;
}
}));
}
}
@Override
public void close() {}
@Override
public boolean requiresLayout() {
return false;
}
}

@ -0,0 +1,72 @@
package eu.dnetlib.functionality.modular.ui.utils;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Lists;
import eu.dnetlib.enabling.common.Stoppable;
import eu.dnetlib.enabling.common.StoppableDetails;
import eu.dnetlib.enabling.common.StoppableDetails.StopStatus;
public class ShutdownUtils {
@Autowired(required = false)
private List<Stoppable> stoppables = Lists.newArrayList();
private StopStatus status = StopStatus.RUNNING;
private static final Log log = LogFactory.getLog(ShutdownUtils.class);
public List<StoppableDetails> listStoppableDetails() {
final List<StoppableDetails> list = Lists.newArrayList();
for (Stoppable s : stoppables) {
list.add(s.getStopDetails());
}
return list;
}
public void stopAll() {
this.status = StopStatus.STOPPING;
for (Stoppable s : stoppables) {
final StoppableDetails info = s.getStopDetails();
if (info.getStatus() == StopStatus.RUNNING) {
log.info("Stopping " + info.getName());
s.stop();
}
}
}
public void resumeAll() {
for (Stoppable s : stoppables) {
final StoppableDetails info = s.getStopDetails();
if (info.getStatus() != StopStatus.RUNNING) {
log.info("Resuming " + info.getName());
s.resume();
}
}
this.status = StopStatus.RUNNING;
}
public StopStatus currentStatus() {
if (status == StopStatus.STOPPING) {
int running = 0;
for (Stoppable s : stoppables) {
final StoppableDetails info = s.getStopDetails();
if (info.getStatus() != StopStatus.STOPPED) {
running++;
}
}
if (running == 0) {
status = StopStatus.STOPPED;
}
}
return status;
}
}

@ -0,0 +1,77 @@
package eu.dnetlib.functionality.modular.ui.workflows.controllers;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import eu.dnetlib.msro.workflows.util.ValidNodeValuesFetcher;
import eu.dnetlib.msro.workflows.util.ValidNodeValuesFetcher.DnetParamValue;
@Controller
public class DnetParamValuesController {
@Resource
private List<ValidNodeValuesFetcher> validNodesFetchers;
private static final Log log = LogFactory.getLog(DnetParamValuesController.class);
@RequestMapping("/ui/**/wf_obtainValidValues.list")
public void obtainValidValues(final HttpServletRequest request,
final HttpServletResponse response,
@RequestParam(value = "bean", required = true) final String bean) throws IOException {
final ValidNodeValuesFetcher fetcher = findValidNodeValuesFetcher(bean);
if (fetcher == null) {
log.error("ValidNodeValuesFetcher not found: " + bean);
sendResponse(response, new ArrayList<ValidNodeValuesFetcher.DnetParamValue>());
} else {
final Map<String, String> params = findParams(request);
sendResponse(response, fetcher.evaluate(params));
}
}
private ValidNodeValuesFetcher findValidNodeValuesFetcher(final String bean) {
for (ValidNodeValuesFetcher fetcher : validNodesFetchers) {
if (fetcher.getName().equals(bean)) { return fetcher; }
}
return null;
}
private Map<String, String> findParams(final HttpServletRequest request) {
final Map<String, String> params = Maps.newHashMap();
final Enumeration<?> e = request.getParameterNames();
while (e.hasMoreElements()) {
final String name = (String) e.nextElement();
params.put(name, request.getParameter(name));
}
return params;
}
private void sendResponse(final HttpServletResponse response, final List<DnetParamValue> values) throws IOException {
Collections.sort(values);
response.setContentType("application/json;charset=UTF-8");
IOUtils.copy(new StringReader(new Gson().toJson(values)), response.getOutputStream());
}
}

@ -0,0 +1,103 @@
package eu.dnetlib.functionality.modular.ui.workflows.controllers;
import java.io.StringWriter;
import java.net.URLEncoder;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ui.ModelMap;
import com.google.gson.Gson;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
import eu.dnetlib.functionality.modular.ui.workflows.objects.sections.WorkflowSectionGrouper;
public class WfEntryPointController extends ModuleEntryPoint {
@Resource
private WorkflowSectionGrouper workflowSectionGrouper;
@Resource
private UniqueServiceLocator serviceLocator;
private static final Log log = LogFactory.getLog(WfEntryPointController.class);
private final Gson gson = new Gson();
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (request.getParameterMap().containsKey("wfId")) {
initialize_direct_wf(map, request);
} else {
initialize_normal(map, request);
}
}
private void initialize_direct_wf(final ModelMap map, final HttpServletRequest request) {
final String wfId = request.getParameter("wfId");
final StringWriter sw = new StringWriter();
sw.append("for $x in collection('/db/DRIVER/MetaWorkflowDSResources/MetaWorkflowDSResourceType') ");
sw.append("where $x//WORKFLOW/@id='");
sw.append(wfId);
sw.append("' return concat(");
sw.append("$x//METAWORKFLOW_SECTION, ");
sw.append("' |=@=| ', ");
sw.append("$x//RESOURCE_IDENTIFIER/@value, ");
sw.append("' |=@=| ', ");
sw.append("$x//DATAPROVIDER/@id, ");
sw.append("' |=@=| ', ");
sw.append("$x//DATAPROVIDER/@interface)");
try {
final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(sw.toString());
if (list.size() > 0) {
final String[] arr = list.get(0).split("\\|=@=\\|");
final String section = arr[0].trim();
final String metaWf = arr[1].trim();
final String repoId = arr[2].trim();
final String repoApi = arr[3].trim();
if (!StringUtils.isEmpty(repoId)
&& !StringUtils.isEmpty(repoApi)
&& !StringUtils.isEmpty(metaWf)
&& !StringUtils.isEmpty(wfId)) {
map.addAttribute("redirect",
"repoApis.do#/api/" +
URLEncoder.encode(repoId, "UTF-8") + "/" +
URLEncoder.encode(repoApi, "UTF-8") + "/" +
URLEncoder.encode(metaWf, "UTF-8") + "/" +
URLEncoder.encode(wfId, "UTF-8"));
} else {
map.addAttribute("initialWf", gson.toJson(wfId));
map.addAttribute("initialMetaWf", gson.toJson(metaWf));
map.addAttribute("section", gson.toJson(section));
}
}
} catch (Exception e) {
log.error("Error obtaining details of wf " + wfId);
}
}
private void initialize_normal(final ModelMap map, final HttpServletRequest request) {
if (request.getParameterMap().containsKey("section")) {
map.addAttribute("section", gson.toJson(request.getParameter("section")));
}
if (request.getParameterMap().containsKey("metaWf")) {
map.addAttribute("initialMetaWf", gson.toJson(request.getParameter("metaWf")));
}
}
}

@ -0,0 +1,22 @@
package eu.dnetlib.functionality.modular.ui.workflows.controllers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class WfHistoryEntryPointController extends ModuleEntryPoint {
@Override
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
if (request.getParameterMap().containsKey("procId")) {
map.addAttribute("procId", request.getParameter("procId"));
}
if (request.getParameterMap().containsKey("family")) {
map.addAttribute("family", request.getParameter("family"));
}
}
}

@ -0,0 +1,18 @@
package eu.dnetlib.functionality.modular.ui.workflows.controllers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
public class WfTimelineEntryPointController extends ModuleEntryPoint {
@Override
protected void initialize(ModelMap map, HttpServletRequest request,
HttpServletResponse response) throws Exception {
}
}

@ -0,0 +1,399 @@
package eu.dnetlib.functionality.modular.ui.workflows.controllers;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.googlecode.sarasvati.GraphProcess;
import com.googlecode.sarasvati.Node;
import com.googlecode.sarasvati.NodeToken;
import com.googlecode.sarasvati.ProcessState;
import eu.dnetlib.common.logging.DnetLogger;
import eu.dnetlib.common.logging.LogMessage;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.functionality.modular.ui.AbstractAjaxController;
import eu.dnetlib.functionality.modular.ui.workflows.objects.AdvancedMetaWorkflowDescriptor;
import eu.dnetlib.functionality.modular.ui.workflows.objects.AtomicWorkflowDescriptor;
import eu.dnetlib.functionality.modular.ui.workflows.objects.MetaWorkflowDescriptor;
import eu.dnetlib.functionality.modular.ui.workflows.objects.NodeInfo;
import eu.dnetlib.functionality.modular.ui.workflows.objects.NodeTokenInfo;
import eu.dnetlib.functionality.modular.ui.workflows.objects.NodeWithUserParams;
import eu.dnetlib.functionality.modular.ui.workflows.objects.ProcessListEntry;
import eu.dnetlib.functionality.modular.ui.workflows.objects.sections.WorkflowSectionGrouper;
import eu.dnetlib.functionality.modular.ui.workflows.sarasvati.viewer.ProcessGraphGenerator;
import eu.dnetlib.functionality.modular.ui.workflows.util.ISLookupClient;
import eu.dnetlib.functionality.modular.ui.workflows.util.ISRegistryClient;
import eu.dnetlib.miscutils.datetime.DateUtils;
import eu.dnetlib.msro.workflows.sarasvati.loader.ProfileToSarasvatiConverter;
import eu.dnetlib.msro.workflows.sarasvati.loader.WorkflowExecutor;
import eu.dnetlib.msro.workflows.sarasvati.registry.GraphProcessRegistry;
import eu.dnetlib.msro.workflows.util.ProcessUtils;
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
/**
* Web controller for the UI
*
* @author Michele Artini
*/
@Controller
public class WorkflowsController extends AbstractAjaxController {
private final class JournalEntryFunction implements Function<Map<String, String>, ProcessListEntry> {
@Override
public ProcessListEntry apply(final Map<String, String> input) {
final String name = input.get(WorkflowsConstants.SYSTEM_WF_PROFILE_NAME);
String repo = "";
if (input.containsKey(WorkflowsConstants.DATAPROVIDER_NAME)) {
repo += input.get(WorkflowsConstants.DATAPROVIDER_NAME);
}
final String procId = input.get(WorkflowsConstants.SYSTEM_WF_PROCESS_ID);
final String wfId = input.get(WorkflowsConstants.SYSTEM_WF_PROFILE_ID);
final String family = input.get(WorkflowsConstants.SYSTEM_WF_PROFILE_FAMILY);
final long date = NumberUtils.toLong(input.get(LogMessage.LOG_DATE_FIELD), 0);
final String status = Boolean.valueOf(input.get(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY)) ? "SUCCESS" : "FAILURE";
return new ProcessListEntry(procId, wfId, name, family, status, date, repo);
}
}
@Resource
private ISLookupClient isLookupClient;
@Resource
private ISRegistryClient isRegistryClient;
@Resource
private GraphProcessRegistry graphProcessRegistry;
@Resource
private ProcessGraphGenerator processGraphGenerator;
@Resource
private WorkflowSectionGrouper workflowSectionGrouper;
@Resource
private WorkflowExecutor workflowExecutor;
@Resource
private ProfileToSarasvatiConverter profileToSarasvatiConverter;
@Resource(name = "msroWorkflowLogger")
private DnetLogger dnetLogger;
private static final Log log = LogFactory.getLog(WorkflowsController.class);
@RequestMapping("/ui/list_metaworkflows.json")
public @ResponseBody List<MetaWorkflowDescriptor> listMetaWorflowsForSection(@RequestParam(value = "section", required = false) final String sectionName, @RequestParam(value = "dsId", required = false) final String dsId)
throws ISLookUpException, IOException {
if (sectionName != null) {
return workflowSectionGrouper.listMetaWorflowsForSection(sectionName);
} else if (dsId != null) {
return workflowSectionGrouper.listMetaWorflowsForDatasource(dsId);
} else {
return Lists.newArrayList();
}
}
@RequestMapping("/ui/wf_metaworkflow.json")
public @ResponseBody AdvancedMetaWorkflowDescriptor getMetaWorkflow(@RequestParam(value = "id", required = true) final String id) throws Exception {
return isLookupClient.getMetaWorkflow(id);
}
@RequestMapping("/ui/wf_atomic_workflow.json")
public @ResponseBody AtomicWorkflowDescriptor getAtomicWorkflow(@RequestParam(value = "id", required = true) final String id) throws Exception {
final AtomicWorkflowDescriptor wf = isLookupClient.getAtomicWorkflow(id);
final String xml = profileToSarasvatiConverter.getSarasvatiWorkflow(id).getWorkflowXml();
wf.setMapContent(processGraphGenerator.getWfDescImageMap(id, xml));
return wf;
}
@RequestMapping("/ui/wf_atomic_workflow.img")
public void showAtomicWorkflow(final HttpServletResponse response, @RequestParam(value = "id", required = true) final String id) throws Exception {
String xml = profileToSarasvatiConverter.getSarasvatiWorkflow(id).getWorkflowXml();
Set<String> notConfiguredNodes = isLookupClient.getNotConfiguredNodes(id);
BufferedImage image = processGraphGenerator.getWfDescImage(id, xml, notConfiguredNodes);
sendImage(response, image);
}
private void sendImage(final HttpServletResponse response, final BufferedImage image) throws IOException {
response.setContentType("image/png");
OutputStream out = response.getOutputStream();
ImageIO.write(image, "png", out);
out.flush();
out.close();
}
@RequestMapping("/ui/wf.start")
public @ResponseBody String startWorkflow(@RequestParam(value = "id", required = true) final String id) throws Exception {
return workflowExecutor.startProcess(id);
}
@RequestMapping("/ui/metawf.start")
public @ResponseBody String startMetaWorkflow(@RequestParam(value = "id", required = true) final String id) throws Exception {
workflowExecutor.startMetaWorkflow(id, true);
return id;
}
@RequestMapping("/ui/wf_workflow_node.json")
public @ResponseBody NodeInfo workflowNode_info(@RequestParam(value = "wf", required = true) final String wfId,
@RequestParam(value = "node", required = true) final String nodeName) throws ISLookUpException, IOException {
return isLookupClient.getNodeInfo(wfId, nodeName);
}
@RequestMapping("/ui/wf_metaworkflow.edit")
public @ResponseBody boolean scheduleMetaWorkflow(@RequestParam(value = "json", required = true) final String json) throws Exception {
final AdvancedMetaWorkflowDescriptor info = (new Gson()).fromJson(json, AdvancedMetaWorkflowDescriptor.class);
log.info("Updating workflow " + info.getName());
final String xml = isLookupClient.getProfile(info.getWfId());
boolean res = isRegistryClient.updateSarasvatiMetaWorkflow(info.getWfId(), xml, info);
return res;
}
@RequestMapping("/ui/clone_metaworkflow.do")
public @ResponseBody String cloneMetaWf(@RequestParam(value = "id", required = true) final String id,
@RequestParam(value = "name", required = true) final String name) throws Exception {
if (name.trim().length() > 0) {
final String xml = isLookupClient.getProfile(id);
SAXReader reader = new SAXReader();
Document doc = reader.read(new StringReader(xml));
doc.selectSingleNode("//METAWORKFLOW_NAME").setText(name);
for (Object o : doc.selectNodes("//WORKFLOW")) {
Element n = (Element) o;
String atomWfXml = isLookupClient.getProfile(n.valueOf("@id"));
String newAtomWfId = isRegistryClient.registerProfile(atomWfXml);
n.addAttribute("id", newAtomWfId);
}
return isRegistryClient.registerProfile(doc.asXML());
} else throw new IllegalArgumentException("Name is empty");
}
@RequestMapping("/ui/wf_proc_node.json")
public @ResponseBody NodeTokenInfo getProcessWorkflowNode(@RequestParam(value = "id", required = true) final String pid,
@RequestParam(value = "node", required = true) final long nid) throws Exception {
final NodeToken token = findNodeToken(pid, nid);
final NodeTokenInfo info = (token == null) ? new NodeTokenInfo(findNodeName(pid, nid)) : new NodeTokenInfo(token);
return info;
}
private NodeToken findNodeToken(final String pid, final long nid) {
final GraphProcess process = graphProcessRegistry.findProcess(pid);
if (process != null) {
for (NodeToken token : process.getNodeTokens()) {
if (token.getNode().getId() == nid) return token;
}
}
return null;
}
private String findNodeName(final String pid, final long nid) {
final GraphProcess process = graphProcessRegistry.findProcess(pid);
if (process != null) {
for (Node node : process.getGraph().getNodes()) {
if (node.getId() == nid) return node.getName();
}
}
return "-";
}
@RequestMapping("/ui/wf_proc.img")
public void showProcessWorkflow(final HttpServletResponse response, @RequestParam(value = "id", required = true) final String id) throws Exception {
BufferedImage image = processGraphGenerator.getProcessImage(id);
sendImage(response, image);
}
@RequestMapping("/ui/wf_proc.kill")
public @ResponseBody boolean killProcessWorkflow(@RequestParam(value = "id", required = true) final String id) throws Exception {
GraphProcess proc = graphProcessRegistry.findProcess(id);
proc.setState(ProcessState.Canceled);
return true;
}
@RequestMapping("/ui/wf_journal.range")
public @ResponseBody Collection<ProcessListEntry> rangeWfJournal(@RequestParam(value = "start", required = true) final String start,
@RequestParam(value = "end", required = true) final String end) throws Exception {
final Map<String, ProcessListEntry> res = Maps.newHashMap();
final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
final DateTime startDate = formatter.parseDateTime(start);
final DateTime endDate = formatter.parseDateTime(end).plusHours(23).plusMinutes(59).plusSeconds(59);
final Iterator<ProcessListEntry> iter = Iterators.transform(dnetLogger.range(startDate.toDate(), endDate.toDate()), new JournalEntryFunction());
while (iter.hasNext()) {
ProcessListEntry e = iter.next();
res.put(e.getProcId(), e);
}
long now = DateUtils.now();
if (startDate.isBefore(now) && endDate.isAfter(now)) {
for (String pid : graphProcessRegistry.listIdentifiers()) {
final GraphProcess proc = graphProcessRegistry.findProcess(pid);
res.put(pid, new ProcessListEntry(pid, proc));
}
}
return res.values();
}
@RequestMapping("/ui/wf_journal.find")
public @ResponseBody Collection<ProcessListEntry> findWfJournal(@RequestParam(value = "wfs", required = true) final String wfs) {
final Map<String, ProcessListEntry> res = Maps.newHashMap();
final Set<String> wfFilter = (new Gson()).fromJson(wfs, new TypeToken<Set<String>>(){}.getType());
for (String wfId : wfFilter) {
final Iterator<ProcessListEntry> iter = Iterators.transform(dnetLogger.find(WorkflowsConstants.SYSTEM_WF_PROFILE_ID, wfId), new JournalEntryFunction());
while (iter.hasNext()) {
ProcessListEntry e = iter.next();
res.put(e.getProcId(), e);
}
}
for (String pid : graphProcessRegistry.listIdentifiers()) {
final GraphProcess proc = graphProcessRegistry.findProcess(pid);
if (wfFilter.contains(ProcessUtils.calculateWfId(proc))) {
res.put(pid, new ProcessListEntry(pid, proc));
}
}
return res.values();
}
@RequestMapping("/ui/wf_journal_byFamily.find")
public @ResponseBody Collection<ProcessListEntry> findWfJournalByFamily(@RequestParam(value = "family", required = true) final String family) throws IOException {
final Iterator<ProcessListEntry> iter = Iterators.transform(dnetLogger.find(WorkflowsConstants.SYSTEM_WF_PROFILE_FAMILY, family), new JournalEntryFunction());
return Lists.newArrayList(iter);
}
@RequestMapping("/ui/wf_journal.get")
public @ResponseBody Map<String, Object> getWfJournalLog(@RequestParam(value = "id", required = true) final String id) throws Exception {
final Map<String, Object> res = Maps.newHashMap();
final Map<String, String> logs = dnetLogger.findOne("system:processId", id);
if (logs != null && !logs.isEmpty()) {
final List<String> keys = Lists.newArrayList(logs.keySet());
Collections.sort(keys);
final List<Map<String, String>> journalEntry = Lists.newArrayList();
for (String k : keys) {
final Map<String, String> m = Maps.newHashMap();
m.put("name", k);
m.put("value", logs.get(k));
journalEntry.add(m);
}
res.put("journal", journalEntry);
}
final GraphProcess process = graphProcessRegistry.findProcess(id);
if (process != null) {
final String mapContent = (process.getState() == ProcessState.Created) ? "" : processGraphGenerator.getProcessImageMap(id);
String status = "";
if (!process.isComplete()) {
status = process.getState().toString().toUpperCase();
} else if ("true".equals(process.getEnv().getAttribute(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY))) {
status = "SUCCESS";
} else {
status = "FAILURE";
}
final String img = (process.getState() == ProcessState.Created) ? "../resources/img/notStarted.gif" : "wf_proc.img?id=" + id + "&t=" + DateUtils.now();
final String name = process.getGraph().getName();
final long startDate = NumberUtils.toLong(process.getEnv().getAttribute(WorkflowsConstants.SYSTEM_START_DATE), 0);
final long endDate = NumberUtils.toLong(process.getEnv().getAttribute(WorkflowsConstants.SYSTEM_END_DATE), 0);
final AtomicWorkflowDescriptor wf = new AtomicWorkflowDescriptor(id, name, status, mapContent, img, true, "auto", "RUNNING", startDate, endDate);
res.put("graph", wf);
}
return res;
}
@RequestMapping("/ui/wf_atomic_workflow.enable")
public @ResponseBody String enableAtomicWf(@RequestParam(value = "id", required = true) final String id,
@RequestParam(value = "start", required = true) final String value) throws Exception {
isRegistryClient.configureWorkflowStart(id, value);
return value;
}
@RequestMapping("/ui/workflow_user_params.json")
public @ResponseBody List<NodeWithUserParams> listWorkflowUserParams(@RequestParam(value = "wf", required = true) final String wfId) throws Exception {
return isLookupClient.listWorkflowUserParams(wfId);
}
@RequestMapping(value="/ui/save_user_params.do")
public @ResponseBody boolean saveWorkflowUserParams(@RequestParam(value = "wf", required = true) final String wfId, @RequestParam(value = "params", required = true) final String jsonParams) throws Exception {
final String xml = isLookupClient.getProfile(wfId);
final List<NodeWithUserParams> params = new Gson().fromJson(jsonParams, new TypeToken<List<NodeWithUserParams>>(){}.getType());
boolean res = isRegistryClient.updateSarasvatiWorkflow(wfId, xml, params);
for (String metaWfId : isLookupClient.listMetaWorflowsForWfId(wfId)) {
if (isLookupClient.isExecutable(metaWfId)) {
isRegistryClient.updateMetaWorkflowStatus(metaWfId, WorkflowStatus.EXECUTABLE);
} else {
isRegistryClient.updateMetaWorkflowStatus(metaWfId, WorkflowStatus.WAIT_USER_SETTINGS);
}
}
return res;
}
}

@ -0,0 +1,52 @@
package eu.dnetlib.functionality.modular.ui.workflows.menu;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import eu.dnetlib.functionality.modular.ui.AbstractMenu;
import eu.dnetlib.functionality.modular.ui.MenuEntry;
import eu.dnetlib.functionality.modular.ui.users.AccessLimited;
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
import eu.dnetlib.functionality.modular.ui.workflows.objects.sections.WorkflowSectionGrouper;
public class InfrastructureManagementGroup extends AbstractMenu implements AccessLimited {
private int order;
@Resource
private WorkflowSectionGrouper workflowSectionGrouper;
@Override
public List<MenuEntry> getEntries() {
final List<String> list = Lists.newArrayList(workflowSectionGrouper.getAllSectionNames());
Collections.sort(list);
List<MenuEntry> res = Lists.newArrayList();
for(int i=0; i<list.size(); i++) {
res.add(new WorkflowSectionEntryPoint(list.get(i), i));
}
return res;
}
@Override
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
@Override
public Set<PermissionLevel> getPermissionLevels() {
return Sets.newHashSet(PermissionLevel.WF_ADMIN, PermissionLevel.IS_ADMIN);
}
}

@ -0,0 +1,28 @@
package eu.dnetlib.functionality.modular.ui.workflows.menu;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import eu.dnetlib.functionality.modular.ui.MenuEntry;
public class WorkflowSectionEntryPoint extends MenuEntry {
public WorkflowSectionEntryPoint(String s, int order) {
setTitle(s);
setMenu(s);
setDescription(s);
setOrder(order);
}
@Override
public String getRelativeUrl() {
try {
return "/ui/workflows.do?section=" + URLEncoder.encode(getMenu(), "UTF-8");
} catch (UnsupportedEncodingException e) {
return "javascript:void(0)";
}
}
}

@ -0,0 +1,51 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import com.google.gson.Gson;
public abstract class AbstractWorkflowDescriptor implements Comparable<AbstractWorkflowDescriptor> {
private String wfId;
private String name;
private String cssClass;
public AbstractWorkflowDescriptor(final String wfId, final String name, final String cssClass) {
super();
this.wfId = wfId;
this.name = name;
this.cssClass = cssClass;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getCssClass() {
return cssClass;
}
public void setCssClass(final String cssClass) {
this.cssClass = cssClass;
}
public String toJson() {
return (new Gson()).toJson(this);
}
public String getWfId() {
return wfId;
}
public void setWfId(final String wfId) {
this.wfId = wfId;
}
@Override
public int compareTo(final AbstractWorkflowDescriptor o) {
return getName().compareTo(o.getName());
}
}

@ -0,0 +1,76 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import java.util.Set;
import com.google.common.collect.Sets;
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
public class AdvancedMetaWorkflowDescriptor extends MetaWorkflowDescriptor {
private String email;
private boolean scheduled;
private String cronExpression;
private int minInterval;
private Set<String> innerWfs = Sets.newHashSet();
private String html;
public AdvancedMetaWorkflowDescriptor(final String id, final String name, final String email,
final boolean scheduled, final String cronExpression, final int minInterval, final WorkflowStatus statusEnum, final String family, final Set<String> innerWfs, final String html) {
super(id, name, statusEnum, family);
this.email = email;
this.scheduled = scheduled;
this.cronExpression = cronExpression;
this.minInterval = minInterval;
this.innerWfs = innerWfs;
this.setHtml(html);
}
public boolean isScheduled() {
return scheduled;
}
public void setScheduled(final boolean scheduled) {
this.scheduled = scheduled;
}
public String getCronExpression() {
return cronExpression;
}
public void setCronExpression(final String cronExpression) {
this.cronExpression = cronExpression;
}
public int getMinInterval() {
return minInterval;
}
public void setMinInterval(final int minInterval) {
this.minInterval = minInterval;
}
public String getEmail() {
return email;
}
public void setEmail(final String email) {
this.email = email;
}
public Set<String> getInnerWfs() {
return innerWfs;
}
public void setInnerWfs(Set<String> innerWfs) {
this.innerWfs = innerWfs;
}
public String getHtml() {
return html;
}
public void setHtml(String html) {
this.html = html;
}
}

@ -0,0 +1,93 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
public class AtomicWorkflowDescriptor extends AbstractWorkflowDescriptor implements WfGraphProvider {
private String mapContent;
private String status;
private String imageUrl;
private boolean ready;
private String start;
private String lastExecutionDate;
private long startDate;
private long endDate;
public AtomicWorkflowDescriptor(final String id, final String name, final String status, final String mapContent,
final String imageUrl, final boolean ready, final String start, final String lastExecutionDate, long startDate, long endDate) {
super(id, name, "");
this.status = status;
this.mapContent = mapContent;
this.imageUrl = imageUrl;
this.ready = ready;
this.start = start;
this.lastExecutionDate = lastExecutionDate;
this.startDate = startDate;
this.endDate = endDate;
}
public long getStartDate() {
return startDate;
}
public void setStartDate(long startDate) {
this.startDate = startDate;
}
public long getEndDate() {
return endDate;
}
public void setEndDate(long endDate) {
this.endDate = endDate;
}
public void setMapContent(final String mapContent) {
this.mapContent = mapContent;
}
public void setImageUrl(final String imageUrl) {
this.imageUrl = imageUrl;
}
@Override
public String getMapContent() {
return mapContent;
}
@Override
public String getImageUrl() {
return imageUrl;
}
public boolean isReady() {
return ready;
}
public void setReady(final boolean ready) {
this.ready = ready;
}
public String getLastExecutionDate() {
return lastExecutionDate;
}
public void setLastExecutionDate(final String lastExecutionDate) {
this.lastExecutionDate = lastExecutionDate;
}
public String getStatus() {
return status;
}
public void setStatus(final String status) {
this.status = status;
}
public String getStart() {
return start;
}
public void setStart(final String start) {
this.start = start;
}
}

@ -0,0 +1,29 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class FilterCollection extends HashMap<String, List<FilterElem>> {
/**
*
*/
private static final long serialVersionUID = 4856177328627952130L;
public FilterCollection() {
super();
}
public void addElement(String collection, FilterElem elem) {
if (!this.containsKey(collection)) {
this.put(collection, new ArrayList<FilterElem>());
}
this.get(collection).add(elem);
}
public void addElement(String collection, String name, String icon, String value) {
addElement(collection, new FilterElem(name, icon, value));
}
}

@ -0,0 +1,38 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
public class FilterElem {
private String name;
private String icon;
private String value;
public FilterElem(String name, String icon, String value) {
super();
this.name = name;
this.icon = icon;
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

@ -0,0 +1,36 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
public class MetaWorkflowDescriptor extends AbstractWorkflowDescriptor {
private WorkflowStatus statusEnum;
private String familyName;
public MetaWorkflowDescriptor(final String id, final String name, final WorkflowStatus statusEnum, final String familyName) {
super(id, name, "");
this.statusEnum = statusEnum;
this.familyName = familyName;
}
public String getStatus() {
return statusEnum.displayName;
}
public WorkflowStatus getStatusEnum() {
return statusEnum;
}
public void setStatusEnum(final WorkflowStatus statusEnum) {
this.statusEnum = statusEnum;
}
public String getFamilyName() {
return familyName;
}
public void setFamilyName(final String familyName) {
this.familyName = familyName;
}
}

@ -0,0 +1,42 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import java.util.List;
import eu.dnetlib.msro.workflows.util.WorkflowParam;
public class NodeInfo {
private String name;
private String description;
private List<WorkflowParam> params;
public NodeInfo(String name, String description, List<WorkflowParam> params) {
this.name = name;
this.description = description;
this.params = params;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<WorkflowParam> getParams() {
return params;
}
public void setParams(List<WorkflowParam> params) {
this.params = params;
}
}

@ -0,0 +1,97 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.googlecode.sarasvati.NodeToken;
public class NodeTokenInfo {
public class EnvParam {
private String name;
private String value;
public EnvParam(final String name, final String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
}
private String name;
private long start;
private long end;
private List<EnvParam> params;
public NodeTokenInfo(final String name) {
super();
this.name = name;
this.start = 0;
this.end = 0;
this.params = Lists.newArrayList();
}
public NodeTokenInfo(final NodeToken token) {
super();
final Date start = token.getCreateDate();
final Date end = token.getCompleteDate();
this.name = token.getNode().getName();
this.start = start == null ? 0 : start.getTime();
this.end = end == null ? 0 : end.getTime();
final Map<String, EnvParam> map = Maps.newHashMap();
for (String name : token.getFullEnv().getAttributeNames()) {
map.put(name, new EnvParam(name, token.getFullEnv().getAttribute(name)));
}
for (String name : token.getEnv().getAttributeNames()) {
map.put(name, new EnvParam(name, token.getEnv().getAttribute(name)));
}
this.params = Lists.newArrayList(map.values());
Collections.sort(this.params, new Comparator<EnvParam>() {
@Override
public int compare(final EnvParam o1, final EnvParam o2) {
if (o1 == null) {
return -1;
} else if (o2 == null) {
return 1;
} else {
return o1.getName().compareTo(o2.getName());
}
}
});
}
public String getName() {
return name;
}
public long getStart() {
return start;
}
public long getEnd() {
return end;
}
public List<EnvParam> getParams() {
return params;
}
}

@ -0,0 +1,44 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import java.util.List;
import eu.dnetlib.msro.workflows.util.WorkflowParam;
public class NodeWithUserParams {
private String node;
private String desc;
private List<WorkflowParam> params;
public NodeWithUserParams() {}
public NodeWithUserParams(final String node, final String desc, final List<WorkflowParam> params) {
this.node = node;
this.desc = desc;
this.params = params;
}
public String getNode() {
return node;
}
public void setNode(final String node) {
this.node = node;
}
public String getDesc() {
return desc;
}
public void setDesc(final String desc) {
this.desc = desc;
}
public List<WorkflowParam> getParams() {
return params;
}
public void setParams(final List<WorkflowParam> params) {
this.params = params;
}
}

@ -0,0 +1,104 @@
package eu.dnetlib.functionality.modular.ui.workflows.objects;
import java.util.Date;
import com.googlecode.sarasvati.GraphProcess;
import eu.dnetlib.msro.workflows.util.ProcessUtils;
public class ProcessListEntry {
private String procId;
private String wfId;
private String name;
private String family;
private String status;
private long date;
private String repo;
public ProcessListEntry() {}
public ProcessListEntry(String procId, String wfId, String name, String family, String status, long date, String repo) {
this.procId = procId;
this.wfId = wfId;
this.name = name;
this.family = family;
this.status = status;
this.date = date;
this.repo = repo;
}
public ProcessListEntry(String procId, String wfId, String name, String family, String status, Date date, String repo) {
this(procId, wfId, name, family, status, dateToLong(date), repo);
}
public ProcessListEntry(final String procId, final GraphProcess process) {
this(procId,
ProcessUtils.calculateWfId(process),
ProcessUtils.calculateName(process),
ProcessUtils.calculateFamily(process),
ProcessUtils.calculateStatus(process),
ProcessUtils.calculateLastActivityDate(process),
ProcessUtils.calculateRepo(process));
}
public String getProcId() {
return procId;
}
public void setProcId(String procId) {
this.procId = procId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getFamily() {
return family;
}
public String getWfId() {
return wfId;
}
public void setWfId(String wfId) {
this.wfId = wfId;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public void setFamily(String family) {
this.family = family;
}
public String getRepo() {
return repo;
}
public void setRepo(String repo) {
this.repo = repo;
}
private static long dateToLong(Date date) {
return (date == null) ? Long.MAX_VALUE : date.getTime();
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save