Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion geoportal_1/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
6 changes: 6 additions & 0 deletions geoportal_1/.project
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
Expand Down
6 changes: 3 additions & 3 deletions geoportal_1/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.7
10 changes: 10 additions & 0 deletions geoportal_1/.settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="geoportal">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="opengeoportal"/>
<property name="java-output-path" value="/geoportal/target/classes"/>
</wb-module>
</project-modules>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
2 changes: 2 additions & 0 deletions geoportal_1/.settings/org.eclipse.wst.validation.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.springframework.ide.eclipse.beans.core.ignoreMissingNamespaceHandler=false
19 changes: 19 additions & 0 deletions geoportal_1/.springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.6.2.201410090854-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/webapp/WEB-INF/sample-cas-security-app-context.xml</config>
<config>src/main/webapp/WEB-INF/security-app-context.xml</config>
</configs>
<autoconfigs>
<config>src/main/webapp/WEB-INF/applicationContext.xml</config>
<config>src/main/webapp/WEB-INF/appServlet-servlet.xml</config>
</autoconfigs>
<configSets>
</configSets>
</beansProjectDescription>
5 changes: 5 additions & 0 deletions geoportal_1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@
<artifactId>eclipselink</artifactId>
<version>2.5.2-M1</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
</dependencies>
<build>
<finalName>${warFile.name}</finalName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected String getUrl(LayerRequest layer) throws Exception{
}


private File getDirectory() throws IOException{
protected File getDirectory() throws IOException{
File downloadDirectory = this.directoryRetriever.getDownloadDirectory();
File newDir = File.createTempFile("OGP", "", downloadDirectory);
newDir.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.net.MalformedURLException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -44,13 +45,24 @@ public String createDownloadRequest() throws Exception {
@Override
public List<String> getUrls(LayerRequest layer) throws MalformedURLException, JsonParseException{
List<String> urls = layer.getDownloadUrl();
for (String currentUrl: urls){
logger.info("download url:" + currentUrl);
try {
this.checkUrl(currentUrl);
} catch (MalformedURLException e){


Iterator<String> iter = urls.iterator();

while(iter.hasNext()){
//TODO: expedient way logic to check if its http download.
//Should be more elegant in future.
String currentUrl = iter.next();
if(currentUrl.contains("http")){
logger.info("download url:" + currentUrl);
try {
this.checkUrl(currentUrl);
} catch (MalformedURLException e){

}
}
else{
iter.remove();
}
}
return urls;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package org.opengeoportal.download.methods;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;
import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.opengeoportal.download.types.LayerRequest;
import org.opengeoportal.utilities.OgpFileUtils;
import org.springframework.scheduling.annotation.AsyncResult;

import com.fasterxml.jackson.core.JsonParseException;

public class FtpFileDownloadMethod extends AbstractDownloadMethod implements PerLayerDownloadMethod {
private static final Boolean INCLUDES_METADATA = false;
private static final String METHOD = "GET";

@Override
public Boolean includesMetadata() {
return INCLUDES_METADATA;
}

@Override
public String getMethod(){
return METHOD;
}

@Override
public Set<String> getExpectedContentType(){
Set<String> expectedContentType = new HashSet<String>();
expectedContentType.add("application/zip");
return expectedContentType;
}

@Override
public Boolean expectedContentTypeMatched(String foundContentType){
//a file download could be anything
return true;
}

@Override
public String createDownloadRequest() throws Exception {
return "";
}

@Override
public List<String> getUrls(LayerRequest layer) throws MalformedURLException, JsonParseException{
List<String> urls = layer.getDownloadUrl();
Iterator<String> iter = urls.iterator();


while(iter.hasNext()){
String currentUrl = iter.next();
if(currentUrl.contains("ftp")){
logger.info("download url:" + currentUrl);
try {
this.checkUrl(currentUrl);
} catch (MalformedURLException e){

}
}
else
urls.remove(currentUrl);
}
return urls;
};

@Override
public Future<Set<File>> download(LayerRequest currentLayer) throws Exception {
this.currentLayer = currentLayer;
currentLayer.setMetadata(this.includesMetadata());

File directory = getDirectory();
Set<File> fileSet = new HashSet<File>();
List<String> urls = this.getUrls(currentLayer);
for (String url: urls){
InputStream inputStream = null;
URL currentURL = new URL(url);
String ftpServerAddress = currentURL.getHost();
String currentPath = currentURL.getPath();

FTPClient ftp = new FTPClient();
int delimiterIndex = currentPath.lastIndexOf("/");
String remoteDirectory = currentPath.substring(0,delimiterIndex);
String fileName = currentPath.substring(delimiterIndex+1);

try{
int reply;
ftp.connect(ftpServerAddress);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
//Although they are open FTP servers, in order to access the files, a anonymous login is necessary.
ftp.login("anonymous", "anonymous");
System.out.println("Connected to " + ftpServerAddress + ".");
System.out.print(ftp.getReplyString());

// After connection attempt, you should check the reply code to verify success.
reply = ftp.getReplyCode();

if(!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
reply = ftp.getReplyCode();

//enter passive mode
ftp.enterLocalPassiveMode();

//change current directory
ftp.changeWorkingDirectory(remoteDirectory);

//check if the file with given name exists on ftp server
try{
FTPFile[] ftpFiles = ftp.listFiles(fileName);
if (ftpFiles != null && ftpFiles.length > 0){
for (FTPFile file: ftpFiles){
if(!file.isFile())
continue;
System.out.println("Found file:" + file.getName());

//transfer the file
inputStream = ftp.retrieveFileStream(file.getName());

//save the file and add to fileset
//TODO: ftp file does not contain MIME type.
File outputFile = OgpFileUtils.createNewFileFromDownload(fileName, "ZIP", directory);
//FileUtils with a BufferedInputStream seems to be the fastest method with a small sample size. requires more testing
BufferedInputStream bufferedIn = null;
try {
bufferedIn = new BufferedInputStream(inputStream);
FileUtils.copyInputStreamToFile(bufferedIn, outputFile);
fileSet.add(outputFile);
} finally {
IOUtils.closeQuietly(bufferedIn);
}
}
}
} catch(IOException e){
e.printStackTrace();
} finally {
ftp.logout();
}
} catch(IOException e) {
e.printStackTrace();
} finally {
if(ftp.isConnected()) {
try {
ftp.disconnect();
} catch(IOException ioe) {
// do nothing
}
}
IOUtils.closeQuietly(inputStream);
}
}
return new AsyncResult<Set<File>>(fileSet);
};
}
14 changes: 11 additions & 3 deletions geoportal_1/src/main/webapp/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
Expand Down Expand Up @@ -204,6 +206,9 @@
<beans:property name="featureSourceToShape" ref="featureSourceToShape.wfs" />
</beans:bean>

<beans:bean id="downloadMethod.ftpfile"
class="org.opengeoportal.download.methods.FtpFileDownloadMethod">
</beans:bean>

<!-- LayerDownloader -->
<beans:bean id="layerDownloader.wfs"
Expand Down Expand Up @@ -242,6 +247,10 @@
class="org.opengeoportal.download.PerLayerDownloader" scope="prototype">
<beans:property name="perLayerDownloadMethod" ref="downloadMethod.geotools.wfs" />
</beans:bean>
<beans:bean id="layerDownloader.ftpfile"
class="org.opengeoportal.download.PerLayerDownloader" scope="prototype">
<beans:property name="perLayerDownloadMethod" ref="downloadMethod.ftpfile" />
</beans:bean>

<!-- HGL specific -->

Expand Down Expand Up @@ -306,5 +315,4 @@
<task:scheduled ref="cleanupDirectory.download" method="cleanupDownloadDirectory"
fixed-rate="${cleanupInterval}" />
</task:scheduled-tasks>

</beans:beans>
2 changes: 1 addition & 1 deletion geoportal_1/src/main/webapp/WEB-INF/ogp.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ apikey.google=
# .external needs to be a web accessible url
# note: currently ogp will use only /select and /terms
solr.url.internal=
solr.url.external=http://geodata.tufts.edu/solr
solr.url.external=http://ec2-54-87-229-228.compute-1.amazonaws.com:8080/solr
#solr.url.external=http://localhost:8080/solr


Expand Down
14 changes: 14 additions & 0 deletions geoportal_1/src/main/webapp/WEB-INF/views/jspf/devincludes.jspf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@
<link rel="stylesheet" href="resources/css/mapDiv.css" type="text/css" />
<link rel="stylesheet" href="resources/css/localize.css"
type="text/css" />
<link rel="stylesheet" href="resources/css/jquery-ui-ogpTheme.custom.css"
type="text/css" />


<!-- ogp javascript library files -->
<script src="//cdn.jsdelivr.net/underscorejs/1.6.0/underscore-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/backbonejs/1.1.2/backbone-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="resources/javascript/jquery.scrollTo-min.js"></script>
<script src="resources/javascript/spinners/spinners/spinners.min.js"></script>
<script src="resources/javascript/jquery.ba-postmessage.min.js"></script>
<script src="//maps.google.com/maps/api/js?v=3.10&sensor=false"></script>
<script src="resources/javascript/openlayers/OpenLayers-2.11/OpenLayers.js"></script>
<script src="resources/javascript/panZoom.js"></script>



<script type="text/javascript" src="resources/javascript/lib/models/config.js"></script>
<script type="text/javascript" src="resources/javascript/lib/utility.js"></script>
Expand Down
Loading