Compare commits

...

2 Commits

651 changed files with 50259 additions and 17 deletions

View File

@ -65,6 +65,11 @@
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>

View File

@ -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;
}
}

View File

@ -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
}
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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. */

View File

@ -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.
*/

View File

@ -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.

View File

@ -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
*

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -0,0 +1,46 @@
package eu.dnetlib.enabling.datasources.common;
public abstract class AggregationInfo {
private int numberOfRecords;
private String date;
private AggregationStage aggregationStage;
private boolean indexedVersion = false;
public AggregationInfo() {}
public int getNumberOfRecords() {
return numberOfRecords;
}
public void setNumberOfRecords(final int numberOfRecords) {
this.numberOfRecords = numberOfRecords;
}
public String getDate() {
return date;
}
public void setDate(final String date) {
this.date = date;
}
public AggregationStage getAggregationStage() {
return aggregationStage;
}
public void setAggregationStage(final AggregationStage aggregationStage) {
this.aggregationStage = aggregationStage;
}
public boolean isIndexedVersion() {
return indexedVersion;
}
public void setIndexedVersion(final boolean indexedVersion) {
this.indexedVersion = indexedVersion;
}
}

View File

@ -0,0 +1,26 @@
package eu.dnetlib.enabling.datasources.common;
/**
* Created by claudio on 12/09/16.
*/
public enum AggregationStage {
COLLECT, TRANSFORM;
public static AggregationStage parse(final String s) {
switch (s) {
case "collect":
case "collection":
case "COLLECT":
case "COLLECTION":
return AggregationStage.COLLECT;
case "transform":
case "transformation":
case "TRANSFORM":
case "TRANSFORMATION":
case "transformDatasets":
case "transformPublications":
return AggregationStage.TRANSFORM;
}
throw new IllegalArgumentException("invalid AggregationStage: " + s);
}
}

View File

@ -0,0 +1,306 @@
package eu.dnetlib.enabling.datasources.common;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
/**
* Api
*/
@MappedSuperclass
public class Api<AP extends ApiParam> implements Comparable<Api<AP>> {
@Id
protected String id = null;
protected String protocol = null;
protected String datasource = null;
protected String contentdescription = null;
protected Boolean active = false;
protected Boolean removable = true;
protected String typology = null;
protected String compatibility;
@Transient
protected boolean compatibilityOverrided = false;
@Column(name = "metadata_identifier_path")
protected String metadataIdentifierPath;
@Column(name = "last_collection_total")
protected Integer lastCollectionTotal;
@Column(name = "last_collection_date")
protected Timestamp lastCollectionDate;
@Column(name = "last_collection_mdid")
protected String lastCollectionMdid;
@Column(name = "last_aggregation_total")
protected Integer lastAggregationTotal;
@Column(name = "last_aggregation_date")
protected Timestamp lastAggregationDate;
@Column(name = "last_aggregation_mdid")
protected String lastAggregationMdid;
@Column(name = "last_download_total")
protected Integer lastDownloadTotal;
@Column(name = "last_download_date")
protected Timestamp lastDownloadDate;
@Column(name = "last_download_objid")
protected String lastDownloadObjid;
@Column(name = "last_validation_job")
protected String lastValidationJob;
protected String baseurl = null;
@OneToMany(mappedBy = "id.api", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
protected Set<AP> apiParams = Sets.newHashSet();
public Api() {}
public String getId() {
return id;
}
public String getProtocol() {
return protocol;
}
public String getDatasource() {
return datasource;
}
public String getContentdescription() {
return contentdescription;
}
public Boolean getActive() {
return active;
}
public Boolean getRemovable() {
return removable;
}
public String getTypology() {
return typology;
}
public String getCompatibility() {
return compatibility;
}
public boolean isCompatibilityOverrided() {
return compatibilityOverrided;
}
public String getMetadataIdentifierPath() {
return metadataIdentifierPath;
}
public Integer getLastCollectionTotal() {
return lastCollectionTotal;
}
public Timestamp getLastCollectionDate() {
return lastCollectionDate;
}
public String getLastCollectionMdid() {
return lastCollectionMdid;
}
public Integer getLastAggregationTotal() {
return lastAggregationTotal;
}
public Timestamp getLastAggregationDate() {
return lastAggregationDate;
}
public String getLastAggregationMdid() {
return lastAggregationMdid;
}
public Integer getLastDownloadTotal() {
return lastDownloadTotal;
}
public Timestamp getLastDownloadDate() {
return lastDownloadDate;
}
public String getLastDownloadObjid() {
return lastDownloadObjid;
}
public String getLastValidationJob() {
return lastValidationJob;
}
public String getBaseurl() {
return baseurl;
}
public Set<AP> getApiParams() {
return apiParams;
}
public Api<AP> setId(final String id) {
this.id = id;
return this;
}
public Api<AP> setProtocol(final String protocol) {
this.protocol = protocol;
return this;
}
public Api<AP> setDatasource(final String datasource) {
this.datasource = datasource;
return this;
}
public Api<AP> setContentdescription(final String contentdescription) {
this.contentdescription = contentdescription;
return this;
}
public Api<AP> setActive(final Boolean active) {
this.active = active;
return this;
}
public Api<AP> setRemovable(final Boolean removable) {
this.removable = removable;
return this;
}
public Api<AP> setTypology(final String typology) {
this.typology = typology;
return this;
}
public Api<AP> setCompatibility(final String compatibility) {
this.compatibility = compatibility;
return this;
}
public Api<AP> setCompatibilityOverrided(final boolean compatibilityOverrided) {
this.compatibilityOverrided = compatibilityOverrided;
return this;
}
public Api<AP> setMetadataIdentifierPath(final String metadataIdentifierPath) {
this.metadataIdentifierPath = metadataIdentifierPath;
return this;
}
public Api<AP> setLastCollectionTotal(final Integer lastCollectionTotal) {
this.lastCollectionTotal = lastCollectionTotal;
return this;
}
public Api<AP> setLastCollectionDate(final Timestamp lastCollectionDate) {
this.lastCollectionDate = lastCollectionDate;
return this;
}
public Api<AP> setLastCollectionMdid(final String lastCollectionMdid) {
this.lastCollectionMdid = lastCollectionMdid;
return this;
}
public Api<AP> setLastAggregationTotal(final Integer lastAggregationTotal) {
this.lastAggregationTotal = lastAggregationTotal;
return this;
}
public Api<AP> setLastAggregationDate(final Timestamp lastAggregationDate) {
this.lastAggregationDate = lastAggregationDate;
return this;
}
public Api<AP> setLastAggregationMdid(final String lastAggregationMdid) {
this.lastAggregationMdid = lastAggregationMdid;
return this;
}
public Api<AP> setLastDownloadTotal(final Integer lastDownloadTotal) {
this.lastDownloadTotal = lastDownloadTotal;
return this;
}
public Api<AP> setLastDownloadDate(final Timestamp lastDownloadDate) {
this.lastDownloadDate = lastDownloadDate;
return this;
}
public Api<AP> setLastDownloadObjid(final String lastDownloadObjid) {
this.lastDownloadObjid = lastDownloadObjid;
return this;
}
public Api<AP> setLastValidationJob(final String lastValidationJob) {
this.lastValidationJob = lastValidationJob;
return this;
}
public Api<AP> setBaseurl(final String baseurl) {
this.baseurl = baseurl;
return this;
}
public Api<AP> setApiParams(final Set<AP> apiParams) {
this.apiParams = apiParams;
return this;
}
@Override
public boolean equals(final Object o) {
if (this == o) { return true; }
if (o == null || getClass() != o.getClass()) { return false; }
final Api<?> api = (Api<?>) o;
return Objects.equals(this.id, api.id);
}
/*
* (non-Javadoc)
*
* @see eu.dnetlib.openaire.exporter.model.datasource.db.ApiInterface#hashCode()
*/
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return new Gson().toJson(this);
}
@Override
public int compareTo(final Api<AP> a) {
return ComparisonChain.start()
.compare(getId(), a.getId())
.result();
}
}

View File

@ -0,0 +1,13 @@
package eu.dnetlib.enabling.datasources.common;
public interface ApiParam {
String getValue();
void setValue(String value);
String getParam();
void setParam(String param);
}

View File

@ -0,0 +1,27 @@
package eu.dnetlib.enabling.datasources.common;
public class ApiParamImpl implements ApiParam {
private String param;
private String value;
@Override
public String getParam() {
return param;
}
@Override
public void setParam(final String param) {
this.param = param;
}
@Override
public String getValue() {
return value;
}
@Override
public void setValue(final String value) {
this.value = value;
}
}

View File

@ -0,0 +1,65 @@
package eu.dnetlib.enabling.datasources.common;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import com.google.common.collect.ComparisonChain;
/**
* Created by claudio on 13/04/2017.
*/
@Embeddable
@MappedSuperclass
public class ApiParamKey<A extends Api> implements Serializable {
/**
*
*/
protected static final long serialVersionUID = 1640636806392015938L;
@ManyToOne
@JoinColumn(name = "api")
protected A api = null;
protected String param;
public ApiParamKey() {}
public String getParam() {
return param;
}
public ApiParamKey setParam(final String param) {
this.param = param;
return this;
}
public A getApi() {
return api;
}
public void setApi(final A api) {
this.api = api;
}
public int hashCode() {
return Objects.hash(getParam(), getApi().getId());
}
@Override
public boolean equals(final Object o) {
if (this == o) { return true; }
if (o == null || getClass() != o.getClass()) { return false; }
ApiParamKey apk = (ApiParamKey) o;
return ComparisonChain.start()
.compare(getParam(), apk.getParam())
.compare(getApi(), apk.getApi())
.result() == 0;
}
}

View File

@ -0,0 +1,31 @@
package eu.dnetlib.enabling.datasources.common;
public class BrowsableField {
private String id;
private String label;
public BrowsableField() {}
public BrowsableField(String id, String label) {
this.id = id;
this.label = label;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -0,0 +1,13 @@
package eu.dnetlib.enabling.datasources.common;
public interface BrowseTerm {
String getTerm();
void setTerm(String term);
long getTotal();
void setTotal(long total);
}

View File

@ -0,0 +1,30 @@
package eu.dnetlib.enabling.datasources.common;
public class BrowseTermImpl implements BrowseTerm {
private String term;
private long total;
public BrowseTermImpl() {}
public BrowseTermImpl(final String term, final int total) {
this.term = term;
this.total = total;
}
public String getTerm() {
return term;
}
public void setTerm(final String term) {
this.term = term;
}
public long getTotal() {
return total;
}
public void setTotal(final long total) {
this.total = total;
}
}

View File

@ -0,0 +1,513 @@
package eu.dnetlib.enabling.datasources.common;
import java.sql.Date;
import java.util.Set;
import javax.persistence.*;
/**
* Datasource
*/
@MappedSuperclass
public class Datasource<ORG extends Organization, ID extends Identity> {
@Id
protected String id;
@Column(nullable = false)
protected String officialname;
protected String englishname;
protected String websiteurl;
protected String logourl;
protected String contactemail;
protected Double latitude;
protected Double longitude;
protected String timezone;
@Column(name = "namespaceprefix", columnDefinition = "bpchar(12)", nullable = false, updatable = false)
protected String namespaceprefix;
protected String languages;
protected String od_contenttypes;
protected String collectedfrom;
protected Date dateofvalidation;
protected String typology;
protected String provenanceaction;
protected Date dateofcollection;
protected String platform;
@Column(name = "activationid")
protected String activationId;
protected String description;
protected Date releasestartdate;
protected Date releaseenddate;
protected String missionstatementurl;
protected Boolean dataprovider;
protected Boolean serviceprovider;
protected String databaseaccesstype;
protected String datauploadtype;
protected String databaseaccessrestriction;
protected String datauploadrestriction;
protected Boolean versioning;
protected String citationguidelineurl;
protected String qualitymanagementkind;
protected String pidsystems;
protected String certificates;
protected String aggregator;
protected String issn;
protected String eissn;
protected String lissn;
protected String registeredby;
private Date registrationdate;
protected String subjects;
protected Boolean managed;
@Column(name = "consenttermsofuse")
protected Boolean consentTermsOfUse;
@Column(name = "fulltextdownload")
protected Boolean fullTextDownload;
@ManyToMany(
cascade = { CascadeType.PERSIST, CascadeType.MERGE },
fetch = FetchType.LAZY)
@JoinTable(
name = "dsm_datasource_organization",
joinColumns = @JoinColumn(name="datasource"),
inverseJoinColumns = @JoinColumn(name="organization"))
protected Set<ORG> organizations;
@ManyToMany(
cascade = { CascadeType.PERSIST, CascadeType.MERGE },
fetch = FetchType.LAZY )
@JoinTable(
name = "dsm_datasourcepids",
joinColumns = @JoinColumn(name = "datasource"),
inverseJoinColumns = @JoinColumn(name = "pid"))
protected Set<ID> identities;
public Datasource() {}
public String getId() {
return id;
}
public String getOfficialname() {
return officialname;
}
public String getEnglishname() {
return englishname;
}
public String getWebsiteurl() {
return websiteurl;
}
public String getLogourl() {
return logourl;
}
public String getContactemail() {
return contactemail;
}
public Double getLatitude() {
return latitude;
}
public Double getLongitude() {
return longitude;
}
public String getTimezone() {
return timezone;
}
public String getNamespaceprefix() {
return namespaceprefix;
}
public String getLanguages() {
return languages;
}
public String getOd_contenttypes() {
return od_contenttypes;
}
public String getCollectedfrom() {
return collectedfrom;
}
public Date getDateofvalidation() {
return dateofvalidation;
}
public String getTypology() {
return typology;
}
public String getProvenanceaction() {
return provenanceaction;
}
public Date getDateofcollection() {
return dateofcollection;
}
public String getPlatform() {
return platform;
}
public String getActivationId() {
return activationId;
}
public String getDescription() {
return description;
}
public Date getReleasestartdate() {
return releasestartdate;
}
public Date getReleaseenddate() {
return releaseenddate;
}
public String getMissionstatementurl() {
return missionstatementurl;
}
public Boolean getDataprovider() {
return dataprovider;
}
public Boolean getServiceprovider() {
return serviceprovider;
}
public String getDatabaseaccesstype() {
return databaseaccesstype;
}
public String getDatauploadtype() {
return datauploadtype;
}
public String getDatabaseaccessrestriction() {
return databaseaccessrestriction;
}
public String getDatauploadrestriction() {
return datauploadrestriction;
}
public Boolean getVersioning() {
return versioning;
}
public String getCitationguidelineurl() {
return citationguidelineurl;
}
public String getQualitymanagementkind() {
return qualitymanagementkind;
}
public String getPidsystems() {
return pidsystems;
}
public String getCertificates() {
return certificates;
}
public String getAggregator() {
return aggregator;
}
public String getIssn() {
return issn;
}
public String getEissn() {
return eissn;
}
public String getLissn() {
return lissn;
}
public String getRegisteredby() {
return registeredby;
}
public Date getRegistrationdate() {
return registrationdate;
}
public String getSubjects() {
return subjects;
}
public Boolean getManaged() {
return managed;
}
public Set<ORG> getOrganizations() {
return organizations;
}
public Set<ID> getIdentities() {
return identities;
}
public Datasource<ORG, ID> setId(final String id) {
this.id = id;
return this;
}
public Datasource<ORG, ID> setOfficialname(final String officialname) {
this.officialname = officialname;
return this;
}
public Datasource<ORG, ID> setEnglishname(final String englishname) {
this.englishname = englishname;
return this;
}
public Datasource<ORG, ID> setWebsiteurl(final String websiteurl) {
this.websiteurl = websiteurl;
return this;
}
public Datasource<ORG, ID> setLogourl(final String logourl) {
this.logourl = logourl;
return this;
}
public Datasource<ORG, ID> setContactemail(final String contactemail) {
this.contactemail = contactemail;
return this;
}
public Datasource<ORG, ID> setLatitude(final Double latitude) {
this.latitude = latitude;
return this;
}
public Datasource<ORG, ID> setLongitude(final Double longitude) {
this.longitude = longitude;
return this;
}
public Datasource<ORG, ID> setTimezone(final String timezone) {
this.timezone = timezone;
return this;
}
public Datasource<ORG, ID> setNamespaceprefix(final String namespaceprefix) {
this.namespaceprefix = namespaceprefix;
return this;
}
public Datasource<ORG, ID> setLanguages(final String languages) {
this.languages = languages;
return this;
}
public Datasource<ORG, ID> setOd_contenttypes(final String od_contenttypes) {
this.od_contenttypes = od_contenttypes;
return this;
}
public Datasource<ORG, ID> setCollectedfrom(final String collectedfrom) {
this.collectedfrom = collectedfrom;
return this;
}
public Datasource<ORG, ID> setDateofvalidation(final Date dateofvalidation) {
this.dateofvalidation = dateofvalidation;
return this;
}
public Datasource<ORG, ID> setTypology(final String typology) {
this.typology = typology;
return this;
}
public Datasource<ORG, ID> setProvenanceaction(final String provenanceaction) {
this.provenanceaction = provenanceaction;
return this;
}
public Datasource<ORG, ID> setDateofcollection(final Date dateofcollection) {
this.dateofcollection = dateofcollection;
return this;
}
public Datasource<ORG, ID> setPlatform(final String platform) {
this.platform = platform;
return this;
}
public Datasource<ORG, ID> setActivationId(final String activationId) {
this.activationId = activationId;
return this;
}
public Datasource<ORG, ID> setDescription(final String description) {
this.description = description;
return this;
}
public Datasource<ORG, ID> setReleasestartdate(final Date releasestartdate) {
this.releasestartdate = releasestartdate;
return this;
}
public Datasource<ORG, ID> setReleaseenddate(final Date releaseenddate) {
this.releaseenddate = releaseenddate;
return this;
}
public Datasource<ORG, ID> setMissionstatementurl(final String missionstatementurl) {
this.missionstatementurl = missionstatementurl;
return this;
}
public Datasource<ORG, ID> setDataprovider(final Boolean dataprovider) {
this.dataprovider = dataprovider;
return this;
}
public Datasource<ORG, ID> setServiceprovider(final Boolean serviceprovider) {
this.serviceprovider = serviceprovider;
return this;
}
public Datasource<ORG, ID> setDatabaseaccesstype(final String databaseaccesstype) {
this.databaseaccesstype = databaseaccesstype;
return this;
}
public Datasource<ORG, ID> setDatauploadtype(final String datauploadtype) {
this.datauploadtype = datauploadtype;
return this;
}
public Datasource<ORG, ID> setDatabaseaccessrestriction(final String databaseaccessrestriction) {
this.databaseaccessrestriction = databaseaccessrestriction;
return this;
}
public Datasource<ORG, ID> setDatauploadrestriction(final String datauploadrestriction) {
this.datauploadrestriction = datauploadrestriction;
return this;
}
public Datasource<ORG, ID> setVersioning(final Boolean versioning) {
this.versioning = versioning;
return this;
}
public Datasource<ORG, ID> setCitationguidelineurl(final String citationguidelineurl) {
this.citationguidelineurl = citationguidelineurl;
return this;
}
public Datasource<ORG, ID> setQualitymanagementkind(final String qualitymanagementkind) {
this.qualitymanagementkind = qualitymanagementkind;
return this;
}
public Datasource<ORG, ID> setPidsystems(final String pidsystems) {
this.pidsystems = pidsystems;
return this;
}
public Datasource<ORG, ID> setCertificates(final String certificates) {
this.certificates = certificates;
return this;
}
public Datasource<ORG, ID> setAggregator(final String aggregator) {
this.aggregator = aggregator;
return this;
}
public Datasource<ORG, ID> setIssn(final String issn) {
this.issn = issn;
return this;
}
public Datasource<ORG, ID> setEissn(final String eissn) {
this.eissn = eissn;
return this;
}
public Datasource<ORG, ID> setLissn(final String lissn) {
this.lissn = lissn;
return this;
}
public Datasource<ORG, ID> setRegisteredby(final String registeredby) {
this.registeredby = registeredby;
return this;
}
public Datasource setRegistrationdate(final Date registrationdate) {
this.registrationdate = registrationdate;
return this;
}
public Datasource<ORG, ID> setSubjects(final String subjects) {
this.subjects = subjects;
return this;
}
public Datasource<ORG, ID> setManaged(final Boolean managed) {
this.managed = managed;
return this;
}
public Datasource<ORG, ID> setOrganizations(final Set<ORG> organizations) {
this.organizations = organizations;
return this;
}
public Datasource<ORG, ID> setIdentities(final Set<ID> identities) {
this.identities = identities;
return this;
}
public Boolean getConsentTermsOfUse() {
return consentTermsOfUse;
}
public void setConsentTermsOfUse(Boolean consentTermsOfUse) {
this.consentTermsOfUse = consentTermsOfUse;
}
public Boolean getFullTextDownload() {
return fullTextDownload;
}
public void setFullTextDownload(Boolean fullTextDownload) {
this.fullTextDownload = fullTextDownload;
}
}

View File

@ -0,0 +1,25 @@
package eu.dnetlib.enabling.datasources.common;
import java.util.List;
public interface DatasourceManagerCommon<DS extends Datasource<?, ?>, API extends Api<?>> {
DS getDs(String id) throws DsmException;
List<? extends API> getApis(String dsId) throws DsmException;
void deleteDs(String dsId) throws DsmException;
void deleteApi(String dsId, String apiId) throws DsmException;
void addApi(API api) throws DsmException;
void setManaged(String id, boolean managed) throws DsmException;
boolean isManaged(String id) throws DsmException;
void saveDs(DS datasource) throws DsmException;
void updateCompliance(String dsId, String apiId, String compliance, boolean override) throws DsmException;
}

View File

@ -0,0 +1,38 @@
package eu.dnetlib.enabling.datasources.common;
public class DsmException extends Exception {
/**
*
*/
private static final long serialVersionUID = 8980196353591772127L;
private int code;
public DsmException(int code, String msg) {
super(msg);
this.code = code;
}
public DsmException(int code, Throwable e) {
super(e);
this.code = code;
}
public DsmException(int code, String msg, Throwable e) {
super(msg, e);
this.code = code;
}
public DsmException(String msg) {
this(500, msg);
}
public int getCode() {
return code;
}
public void setCode(final int code) {
this.code = code;
}
}

View File

@ -0,0 +1,34 @@
package eu.dnetlib.enabling.datasources.common;
public class DsmForbiddenException extends Exception {
private int code;
public DsmForbiddenException(int code, String msg) {
super(msg);
this.code = code;
}
public DsmForbiddenException(int code, Throwable e) {
super(e);
this.code = code;
}
public DsmForbiddenException(int code, String msg, Throwable e) {
super(msg, e);
this.code = code;
}
public DsmForbiddenException(String msg) {
this(403, msg);
}
public int getCode() {
return code;
}
public void setCode(final int code) {
this.code = code;
}
}

View File

@ -0,0 +1,33 @@
package eu.dnetlib.enabling.datasources.common;
public class DsmNotFoundException extends Exception {
private int code;
public DsmNotFoundException(int code, String msg) {
super(msg);
this.code = code;
}
public DsmNotFoundException(int code, Throwable e) {
super(e);
this.code = code;
}
public DsmNotFoundException(int code, String msg, Throwable e) {
super(msg, e);
this.code = code;
}
public DsmNotFoundException(String msg) {
this(404, msg);
}
public int getCode() {
return code;
}
public void setCode(final int code) {
this.code = code;
}
}

View File

@ -0,0 +1,22 @@
package eu.dnetlib.enabling.datasources.common;
public class DsmRuntimeException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 8980196353591772127L;
public DsmRuntimeException(String msg) {
super(msg);
}
public DsmRuntimeException(String msg, Throwable e) {
super(msg, e);
}
public DsmRuntimeException(Throwable e) {
super(e);
}
}

View File

@ -0,0 +1,37 @@
package eu.dnetlib.enabling.datasources.common;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
/**
* Created by claudio on 13/04/2017.
*/
@MappedSuperclass
public class Identity {
@Id
protected String pid;
protected String issuertype;
public Identity() {}
public String getPid() {
return this.pid;
}
public String getIssuertype() {
return this.issuertype;
}
public Identity setPid(final String pid) {
this.pid = pid;
return this;
}
public Identity setIssuertype(final String issuertype) {
this.issuertype = issuertype;
return this;
}
}

View File

@ -0,0 +1,38 @@
package eu.dnetlib.enabling.datasources.common;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface LocalDatasourceManager<DS extends Datasource<?, ?>, API extends Api<?>> extends DatasourceManagerCommon<DS, API> {
Set<String> listManagedDatasourceIds() throws DsmRuntimeException;
List<SimpleDatasource> searchDatasourcesByType(String type) throws DsmException;
List<? extends SearchApisEntry> searchApis(String field, Object value) throws DsmException;
List<? extends BrowsableField> listBrowsableFields() throws DsmException;
List<? extends BrowseTerm> browseField(String field) throws DsmException;
void setActive(String dsId, String apiId, boolean active) throws DsmException;
boolean isActive(String dsId, String apiId) throws DsmException;
void setLastCollectionInfo(String dsId, String apiId, String mdId, Integer size, Date date) throws DsmException;
void setLastAggregationInfo(String dsId, String apiId, String mdId, Integer size, Date date) throws DsmException;
void setLastDownloadInfo(String dsId, String apiId, String objId, Integer size, Date date) throws DsmException;
void setLastValidationJob(String dsId, String apiId, String jobId) throws DsmException;
void updateApiDetails(String dsId, String apiId, String metadataIdentifierPath, String baseUrl, Map<String, String> params) throws DsmException;
boolean isRemovable(String dsId, String apiId) throws DsmException;
void regenerateProfiles() throws DsmException;
}

View File

@ -0,0 +1,117 @@
package eu.dnetlib.enabling.datasources.common;
import java.sql.Date;
import java.util.Set;
import javax.persistence.*;
@MappedSuperclass
public class Organization<DS extends Datasource<?, ?>> {
@Id
protected String id;
protected String legalshortname;
protected String legalname;
protected String websiteurl;
protected String logourl;
protected String country;
protected String collectedfrom;
protected Date dateofcollection;
protected String provenanceaction;
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, mappedBy = "organizations")
protected Set<DS> datasources;
public Organization() {}
public String getId() {
return id;
}
public String getLegalshortname() {
return legalshortname;
}
public String getLegalname() {
return legalname;
}
public String getWebsiteurl() {
return websiteurl;
}
public String getLogourl() {
return logourl;
}
public String getCountry() {
return country;
}
public String getCollectedfrom() {
return collectedfrom;
}
public Date getDateofcollection() {
return dateofcollection;
}
public String getProvenanceaction() {
return provenanceaction;
}
public Organization<DS> setId(final String id) {
this.id = id;
return this;
}
public Organization<DS> setLegalshortname(final String legalshortname) {
this.legalshortname = legalshortname;
return this;
}
public Organization<DS> setLegalname(final String legalname) {
this.legalname = legalname;
return this;
}
public Organization<DS> setWebsiteurl(final String websiteurl) {
this.websiteurl = websiteurl;
return this;
}
public Organization<DS> setLogourl(final String logourl) {
this.logourl = logourl;
return this;
}
public Organization<DS> setCountry(final String country) {
this.country = country;
return this;
}
public Organization<DS> setCollectedfrom(final String collectedfrom) {
this.collectedfrom = collectedfrom;
return this;
}
public Organization<DS> setDateofcollection(final Date dateofcollection) {
this.dateofcollection = dateofcollection;
return this;
}
public Organization<DS> setProvenanceaction(final String provenanceaction) {
this.provenanceaction = provenanceaction;
return this;
}
public Set<DS> getDatasources() {
return datasources;
}
public void setDatasources(final Set<DS> datasources) {
this.datasources = datasources;
}
}

View File

@ -0,0 +1,139 @@
package eu.dnetlib.enabling.datasources.common;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class SearchApisEntry implements Comparable<SearchApisEntry> {
private String id;
private String compliance;
private String protocol;
private boolean active;
private String repoId = "unknown";
private String repoName = "unknown";
private String alternativeName = "unknown";
private String repoOrganization = "unknown";
private String repoCountry = "-";
private String repoPrefix = "";
private String aggrDate = "";
private int aggrTotal = 0;
public SearchApisEntry() {}
public SearchApisEntry(final String id, final String compliance, final String protocol, final boolean active, final String repoId,
final String repoName, final String repoCountry,
final String repoPrefix, final String aggrDate, final int aggrTotal) {
this.id = id;
this.compliance = compliance;
this.protocol = protocol;
this.active = active;
this.repoId = repoId;
this.repoName = repoName;
this.repoCountry = repoCountry;
this.repoPrefix = repoPrefix;
this.aggrDate = aggrDate;
this.aggrTotal = aggrTotal;
}
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getCompliance() {
return compliance;
}
public void setCompliance(final String compliance) {
this.compliance = compliance;
}
public boolean isActive() {
return active;
}
public void setActive(final boolean active) {
this.active = active;
}
public String getRepoId() {
return repoId;
}
public void setRepoId(final String repoId) {
this.repoId = repoId;
}
public String getRepoName() {
return repoName;
}
public void setRepoName(final String repoName) {
this.repoName = repoName;
}
public String getRepoCountry() {
return repoCountry;
}
public void setRepoCountry(final String repoCountry) {
this.repoCountry = repoCountry;
}
public String getRepoPrefix() {
return repoPrefix;
}
public void setRepoPrefix(final String repoPrefix) {
this.repoPrefix = repoPrefix;
}
@Override
public int compareTo(final SearchApisEntry e) {
return compliance.compareTo(e.getCompliance());
}
public String getAggrDate() {
return aggrDate;
}
public void setAggrDate(final String aggrDate) {
this.aggrDate = aggrDate;
}
public int getAggrTotal() {
return aggrTotal;
}
public void setAggrTotal(final int aggrTotal) {
this.aggrTotal = aggrTotal;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(final String protocol) {
this.protocol = protocol;
}
public String getAlternativeName() {
return alternativeName;
}
public void setAlternativeName(String alternativeName) {
this.alternativeName = alternativeName;
}
public String getRepoOrganization() {
return repoOrganization;
}
public void setRepoOrganization(String repoOrganization) {
this.repoOrganization = repoOrganization;
}
}

View File

@ -0,0 +1,68 @@
package eu.dnetlib.enabling.datasources.common;
import java.util.HashSet;
import java.util.Set;
public class SimpleDatasource implements Comparable<SimpleDatasource> {
private String id;
private String name;
private String typology;
private String origId;
private Set<String> apis = new HashSet<>();
private boolean valid;
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public boolean isValid() {
return valid;
}
public void setValid(final boolean valid) {
this.valid = valid;
}
public String getTypology() {
return typology;
}
public void setTypology(final String typology) {
this.typology = typology;
}
public String getOrigId() {
return origId;
}
public void setOrigId(final String origId) {
this.origId = origId;
}
public Set<String> getApis() {
return apis;
}
public void setApis(final Set<String> apis) {
this.apis = apis;
}
@Override
public int compareTo(final SimpleDatasource e) {
return getName().compareTo(e.getName());
}
}

View File

@ -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());
}
}

View File

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

53
dnet-modular-ui/pom.xml Normal file
View File

@ -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>

View File

@ -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));
}
}

View File

@ -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());
}
}

View File

@ -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));
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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 "";
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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) {}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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 {}
}

View File

@ -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;
}
}

View File

@ -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 {}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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 {
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -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]);
}
}

View File

@ -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 {
}
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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"));
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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 {
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -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 {}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

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

View File

@ -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);
}

View File

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

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

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