Project

General

Profile

« Previous | Next » 

Revision 47859

[maven-release-plugin] copy for tag dnet-download-service-rmi-1.3.3

View differences:

modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-download-service-rmi/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-download-service-rmi"}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/test/java/eu/dnetlib/data/download/rmi/DownloadItemTest.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
import junit.framework.Assert;
4

  
5
/**
6
 * Created by sandro on 3/21/14.
7
 */
8
public class DownloadItemTest {
9

  
10
	@org.junit.Test
11
	public void testGetFileName() throws Exception {
12
		DownloadItem di = new DownloadItem();
13
		di.setIdItemMetadata("id1");
14
		di.setUrl("http://www.test.com");
15
		di.setFileName("testFile");
16
		Assert.assertEquals("testFile", di.getFileName());
17
	}
18
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/main/java/eu/dnetlib/data/download/rmi/DownloadPluginException.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
public class DownloadPluginException extends RuntimeException {
4

  
5
	/**
6
	 *
7
	 */
8
	private static final long serialVersionUID = -8480343562060711656L;
9

  
10
	public DownloadPluginException(final String string, final Throwable exception) {
11
		super(string, exception);
12
	}
13

  
14
	public DownloadPluginException(final Throwable exception) {
15
		super(exception);
16
	}
17

  
18
	public DownloadPluginException(final String msg) {
19
		super(msg);
20

  
21
	}
22

  
23
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/main/java/eu/dnetlib/data/download/rmi/DownloadItem.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
import java.util.Date;
4

  
5
import com.google.gson.Gson;
6
import eu.dnetlib.miscutils.functional.hash.Hashing;
7

  
8
// TODO: Auto-generated Javadoc
9
/**
10
 * Download Item Class that serialize information in the resultset.
11
 */
12

  
13
public class DownloadItem {
14

  
15
	/** The id item metadata. */
16
	private String idItemMetadata;
17
	/**
18
	 * The url.
19
	 */
20
	private String url;
21
	/** The file name. */
22
	private String fileName;
23
	/** The original URL should be appear instead of the downloaded URL. */
24
	private String originalUrl;
25
	/** The open access. */
26
	private OpenAccessValues openAccess;
27
	/** The embargo date. */
28
	private Date embargoDate;
29

  
30
	/**
31
	 * From json.
32
	 *
33
	 * @param inputJson
34
	 *            the input json
35
	 * @return the download item
36
	 */
37
	public static DownloadItem newObjectfromJSON(final String inputJson) {
38
		Gson g = new Gson();
39
		DownloadItem instance = g.fromJson(inputJson, DownloadItem.class);
40
		return instance;
41
	}
42

  
43
	/**
44
	 * To json.
45
	 *
46
	 * @return the string
47
	 */
48
	public String toJSON() {
49
		return new Gson().toJson(this).replace("\\u003d", "=").replace("\\u0026", "&");
50
	}
51

  
52
	/**
53
	 * Gets the id item metadata.
54
	 *
55
	 * @return the id item metadata
56
	 */
57
	public String getIdItemMetadata() {
58
		return idItemMetadata;
59
	}
60

  
61
	/**
62
	 * Sets the id item metadata.
63
	 *
64
	 * @param idItemMetadata
65
	 *            the new id item metadata
66
	 */
67
	public void setIdItemMetadata(final String idItemMetadata) {
68
		this.idItemMetadata = idItemMetadata;
69
	}
70

  
71
	/**
72
	 * Gets the url.
73
	 *
74
	 * @return the url
75
	 */
76
	public String getUrl() {
77
		if (url == null) return url;
78
		return url.replace("\\u003d", "=").replace("\\u0026", "&");
79
	}
80

  
81
	/**
82
	 * Sets the url.
83
	 *
84
	 * @param url
85
	 *            the new url
86
	 */
87
	public void setUrl(final String url) {
88
		this.url = url;
89

  
90
	}
91

  
92
	/**
93
	 * Gets the original url.
94
	 *
95
	 * @return the originalUrl
96
	 */
97
	public String getOriginalUrl() {
98
		if (originalUrl == null) return originalUrl;
99
		return originalUrl.replace("\\u003d", "=").replace("\\u0026", "&");
100
	}
101

  
102
	/**
103
	 * Sets the original url.
104
	 *
105
	 * @param originalUrl
106
	 *            the originalUrl to set
107
	 */
108
	public void setOriginalUrl(final String originalUrl) {
109
		this.originalUrl = originalUrl;
110

  
111
	}
112

  
113
	/**
114
	 * Gets the file name.
115
	 *
116
	 * @return the file name
117
	 */
118
	public String getFileName() {
119
		if ((fileName == null) || "".equals(fileName)) return getIdItemMetadata() + "::" + Hashing.md5(getOriginalUrl());
120
		return fileName;
121
	}
122

  
123
	/**
124
	 * Sets the file name.
125
	 *
126
	 * @param fileName
127
	 *            the new file name
128
	 */
129
	public void setFileName(final String fileName) {
130
		this.fileName = fileName;
131
	}
132

  
133
	/**
134
	 * Gets the open access.
135
	 *
136
	 * @return the openAccess
137
	 */
138
	public String getOpenAccess() {
139
		return openAccess.toString();
140
	}
141

  
142
	/**
143
	 * Sets the open access.
144
	 *
145
	 * @param openAccess
146
	 *            the openAccess to set
147
	 */
148
	public void setOpenAccess(final String openAccess) {
149
		for (OpenAccessValues oaValue : OpenAccessValues.values()) {
150
			if (oaValue.toString().trim().toLowerCase().equals(openAccess.trim().toLowerCase())) {
151
				this.openAccess = oaValue;
152
				return;
153
			}
154
		}
155
		this.openAccess = OpenAccessValues.UNKNOWN;
156
	}
157

  
158
	/**
159
	 * Gets the embargo date.
160
	 *
161
	 * @return the embargoDate
162
	 */
163
	public Date getEmbargoDate() {
164
		return embargoDate;
165
	}
166

  
167
	/**
168
	 * Sets the embargo date.
169
	 *
170
	 * @param embargoDate
171
	 *            the embargoDate to set
172
	 */
173
	public void setEmbargoDate(final Date embargoDate) {
174
		this.embargoDate = embargoDate;
175
	}
176

  
177
	public enum OpenAccessValues {
178
		OPEN, RESTRICTED, CLOSED, EMBARGO, UNKNOWN
179
	}
180
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/main/java/eu/dnetlib/data/download/rmi/DownloadPlugin.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
import java.util.List;
4

  
5
/**
6
 * The DownloadPluin should retrieve the correct URL of the file to download
7
 */
8
public interface DownloadPlugin {
9

  
10
    /**
11
     * If Sets the base path, the plugin will start to download from the basePath in the file system
12
     *
13
     * @param basePath the base path
14
     */
15
    void setBasePath(String basePath);
16

  
17
    /**
18
     * This method retrieve the correct Url of the file from the starting URL
19
     *
20
     * @param item the starting url
21
     * @return the Url of the correct file
22
     */
23
    DownloadItem retrieveUrl(DownloadItem item) throws DownloadPluginException;
24

  
25
    /**
26
     * This method retrieve the correct Url of the file from a list of starting URL
27
     *
28
     * @param items the list of starting url
29
     * @return the list of the file URL
30
     */
31
    Iterable<DownloadItem> retrieveUrls(Iterable<DownloadItem> items) throws DownloadPluginException;
32

  
33
    /**
34
     * Get the name of the plugin
35
     *
36
     * @return the name of the plugin
37
     */
38
    String getPluginName();
39

  
40
    /**
41
     * Gets the regular expression.
42
     *
43
     * @return the regular expression
44
     */
45
    List<String> getRegularExpression();
46

  
47
    /**
48
     * Sets the regular expression.
49
     *
50
     * @param regularExpression the new regular expression
51
     */
52
    void setRegularExpression(final List<String> regularExpression);
53

  
54
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/main/java/eu/dnetlib/data/download/rmi/DownloadServiceException.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
import eu.dnetlib.common.rmi.RMIException;
4

  
5
public class DownloadServiceException extends RMIException {
6

  
7
	/**
8
	 *
9
	 */
10
	private static final long serialVersionUID = -5031281288958769185L;
11

  
12
	public DownloadServiceException(final String string) {
13
		super(string);
14
	}
15

  
16
	public DownloadServiceException(final String string, final Throwable exception) {
17
		super(string, exception);
18
	}
19

  
20
	public DownloadServiceException(final Throwable exception) {
21
		super(exception);
22
	}
23

  
24
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/main/java/eu/dnetlib/data/download/rmi/DownloadPluginEnumerator.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
import java.util.Map;
4

  
5
import org.springframework.beans.factory.BeanFactoryAware;
6

  
7
public interface DownloadPluginEnumerator extends BeanFactoryAware {
8
	
9
	/**
10
	 * Get all beans implementing the DownloadPlugin interface, hashed by name.
11
	 * 
12
	 * @return the map of available download plugins
13
	 */
14
	Map<String, DownloadPlugin> getAll();
15
	
16
	/**
17
	 * Get all beans implementing the DownloadPlugin interface, hashed by protocol name.
18
	 * 
19
	 * @return the map of available download plugins
20
	 */
21
	Map<String, DownloadPlugin> getByProtocols();
22
	
23
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/main/java/eu/dnetlib/data/download/rmi/DownloadService.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
import java.util.List;
4

  
5
import javax.jws.WebMethod;
6
import javax.jws.WebService;
7
import javax.xml.ws.wsaddressing.W3CEndpointReference;
8

  
9
import eu.dnetlib.common.rmi.BaseService;
10

  
11
/**
12
 *
13
 */
14
@WebService(targetNamespace = "http://services.dnetlib.eu/")
15
public interface DownloadService extends BaseService {
16

  
17
	/**
18
	 * Download the file in the resultset to the objectStore.
19
	 *
20
	 * @param resultSet
21
	 *            the resultset of the url Object
22
	 * @param plugin
23
	 *            the name of the plugin to be applied to retrieve the URL
24
	 * @param objectStoreID
25
	 *            the object store id where download the file
26
	 * @throws DownloadServiceException
27
	 *             the download service exception
28
	 */
29
	@WebMethod(operationName = "downloadFromResultSet", action = "downloadFromResultSet")
30
	public void downloadFromResultSet(W3CEndpointReference resultSet, String plugin, String objectStoreID, String protocol, String mimeType)
31
			throws DownloadServiceException;
32

  
33
	@WebMethod(operationName = "listPlugins", action = "listPlugins")
34
	public List<String> listPlugins() throws DownloadServiceException;
35

  
36
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/src/main/java/eu/dnetlib/data/download/rmi/AbstractDownloadPlugin.java
1
package eu.dnetlib.data.download.rmi;
2

  
3
import java.util.List;
4

  
5
import com.google.gson.Gson;
6
import eu.dnetlib.data.download.rmi.DownloadItem.OpenAccessValues;
7
import org.joda.time.DateTime;
8
import org.joda.time.Days;
9

  
10
// TODO: Auto-generated Javadoc
11

  
12
/**
13
 * The Class AbstractDownloadPlugin.
14
 */
15
public abstract class AbstractDownloadPlugin {
16

  
17
	public static final int DEFAULT_TIMEOUT = 5000;
18

  
19
    /**
20
     * The regular expression.
21
     */
22
    protected List<String> regularExpression;
23

  
24

  
25
    /**
26
     * Check open access.
27
     *
28
     * @param input the input
29
     * @return the download item
30
     */
31
    public DownloadItem checkOpenAccess(final DownloadItem input) {
32
        if (input != null) {
33
            OpenAccessValues openAccess = OpenAccessValues.valueOf(input.getOpenAccess());
34
            switch (openAccess) {
35
                case OPEN:
36
                    return input;
37
                case CLOSED:
38
                case RESTRICTED:
39
                case UNKNOWN:
40
                    return null;
41
                case EMBARGO:
42
                    if (input.getEmbargoDate() == null) return null;
43
                    DateTime embargoDate = new DateTime(input.getEmbargoDate());
44
                    DateTime today = new DateTime();
45
                    Days days = Days.daysBetween(embargoDate, today);
46
                    if (days.getDays() <= 0) return input;
47
                    return null;
48
            }
49
        }
50
        return null;
51
    }
52

  
53

  
54
    public DownloadItem filterByRegexp(final DownloadItem input) {
55
        if (this.regularExpression != null && this.regularExpression.size() > 0) {
56
            final String baseURLs = input.getUrl();
57
            final List<String> urlsList = new Gson().fromJson(baseURLs, List.class);
58

  
59
            for (final String baseURL : urlsList) {
60
                for (final String regExp : regularExpression) {
61
                    if (baseURL.matches(regExp))
62
                        return input;
63
                }
64
            }
65
            return null;
66
        } else return input;
67
    }
68

  
69
    protected boolean checkUrlsNotNull(DownloadItem input, List<String> urls) {
70
        for (String s : urls) {
71
            String newURL = extractURL(s);
72
            if (newURL != null) {
73
                input.setOriginalUrl(s);
74
                input.setUrl(newURL);
75
                return true;
76
            }
77
        }
78
        return false;
79
    }
80

  
81
	public abstract String extractURL(final String baseURL) throws DownloadPluginException;
82

  
83

  
84
    /**
85
     * Gets the regular expression.
86
     *
87
     * @return the regular expression
88
     */
89
    public List<String> getRegularExpression() {
90
        return regularExpression;
91
    }
92

  
93

  
94
    /**
95
     * Sets the regular expression.
96
     *
97
     * @param regularExpression the new regular expression
98
     */
99
    public void setRegularExpression(final List<String> regularExpression) {
100
        this.regularExpression = regularExpression;
101
    }
102

  
103
}
modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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/xsd/maven-4.0.0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet45-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>dnet-download-service-rmi</artifactId>
12
	<version>1.3.3</version>
13
	<scm>
14
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-download-service-rmi/tags/dnet-download-service-rmi-1.3.3</developerConnection>
15
	</scm>
16
	<dependencies>
17
		<dependency>
18
			<groupId>eu.dnetlib</groupId>
19
			<artifactId>cnr-rmi-api</artifactId>
20
			<version>[2.0.0,3.0.0)</version>
21
		</dependency>
22
		<dependency>
23
			<groupId>eu.dnetlib</groupId>
24
			<artifactId>cnr-misc-utils</artifactId>
25
			<version>[1.0.0,2.0.0)</version>
26
		</dependency>
27
		<dependency>
28
			<groupId>com.google.code.gson</groupId>
29
			<artifactId>gson</artifactId>
30
			<version>${google.gson.version}</version>
31
		</dependency>
32
		<dependency>
33
			<groupId>junit</groupId>
34
			<artifactId>junit</artifactId>
35
			<version>${junit.version}</version>
36
			<scope>test</scope>
37
		</dependency>
38

  
39
		<dependency>
40
			<groupId>org.springframework</groupId>
41
			<artifactId>spring-beans</artifactId>
42
			<version>${spring.version}</version>
43
		</dependency>
44
		<dependency>
45
			<groupId>joda-time</groupId>
46
			<artifactId>joda-time</artifactId>
47
			<version>2.9</version>
48
		</dependency>
49

  
50
	</dependencies>
51

  
52

  
53
</project>

Also available in: Unified diff