migrated to sbt-misc-plugin
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
package com.oggio88.jpacrepo.annotation;
|
||||
|
||||
import javax.ws.rs.NameBinding;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@NameBinding
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CORSManaged
|
||||
{
|
||||
}
|
@@ -8,6 +8,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -30,8 +31,6 @@ public class ApplicationContext
|
||||
|
||||
public boolean invalidateCache = true;
|
||||
|
||||
public boolean cors_enabled;
|
||||
|
||||
public ApplicationContext(String propertyFile)
|
||||
{
|
||||
systemProperties = new Properties();
|
||||
@@ -40,11 +39,10 @@ public class ApplicationContext
|
||||
try
|
||||
{
|
||||
input = new FileInputStream(propertyFile);
|
||||
// load a properties file
|
||||
systemProperties.load(input);
|
||||
// get the property value and print it out
|
||||
systemProperties.getProperty("RepoFolder");
|
||||
repoFolder = systemProperties.getProperty("RepoFolder");
|
||||
repoFolder = Optional.ofNullable(
|
||||
System.getProperty("com.oggio88.jpacrepo.RepoFolder")).orElse(
|
||||
systemProperties.getProperty("RepoFolder"));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@@ -64,10 +62,6 @@ public class ApplicationContext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String prop = System.getProperty("org.oggio88.jpacrepo.cors");
|
||||
if (prop != null)
|
||||
cors_enabled = Boolean.parseBoolean(prop);
|
||||
}
|
||||
|
||||
public Properties getSystemProperties()
|
||||
|
@@ -24,7 +24,6 @@ public class ApplicationConfig extends Application
|
||||
{
|
||||
HashSet<Class<?>> c = new HashSet<>();
|
||||
c.add(PacmanWebService.class);
|
||||
c.add(CORSFilter.class);
|
||||
classes = Collections.unmodifiableSet(c);
|
||||
}
|
||||
|
||||
|
@@ -1,38 +0,0 @@
|
||||
package com.oggio88.jpacrepo.service;
|
||||
|
||||
import com.oggio88.jpacrepo.annotation.CORSManaged;
|
||||
import com.oggio88.jpacrepo.context.ApplicationContext;
|
||||
import com.oggio88.jpacrepo.context.DefaultConfiguration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerResponseContext;
|
||||
import javax.ws.rs.container.ContainerResponseFilter;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Provider
|
||||
@CORSManaged
|
||||
public class CORSFilter implements ContainerResponseFilter
|
||||
{
|
||||
private final Logger log = Logger.getLogger(CORSFilter.class.getName());
|
||||
|
||||
@Inject
|
||||
@DefaultConfiguration
|
||||
ApplicationContext ctx;
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext containerRequestContext,
|
||||
ContainerResponseContext containerResponseContext) throws IOException
|
||||
{
|
||||
if (!ctx.cors_enabled)
|
||||
{
|
||||
MultivaluedMap<String, Object> headers = containerResponseContext.getHeaders();
|
||||
headers.add("Access-Control-Allow-Origin", "*");
|
||||
headers.add("Access-Control-Allow-Headers", "Accept, Accept-Language, Content-Language, Content-Type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -13,10 +13,10 @@ import java.util.Map;
|
||||
@Local
|
||||
public interface PacmanServiceView extends PacmanServiceRemote
|
||||
{
|
||||
public long countResults(String name, String version, String arch);
|
||||
long countResults(String name, String version, String arch);
|
||||
|
||||
public List<PkgData> searchPackage(String name, String version, String arch, int page, int pageSize);
|
||||
List<PkgData> searchPackage(String name, String version, String arch, int page, int pageSize);
|
||||
|
||||
public<T> List<T> listProperty(String property, Map<String,String> equalityConditions, Class<T> cls);
|
||||
<T> List<T> listProperty(String property, Map<String,String> equalityConditions, Class<T> cls);
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.oggio88.jpacrepo.service;
|
||||
|
||||
import com.oggio88.jpacrepo.annotation.CORSManaged;
|
||||
import com.oggio88.jpacrepo.context.ApplicationContext;
|
||||
import com.oggio88.jpacrepo.context.DefaultConfiguration;
|
||||
import com.oggio88.jpacrepo.model.PkgData;
|
||||
@@ -43,7 +42,6 @@ class PkgTuple
|
||||
public long size;
|
||||
}
|
||||
|
||||
@CORSManaged
|
||||
@Singleton
|
||||
@Path("/pkg")
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
||||
|
@@ -17,14 +17,16 @@ import java.io.File;
|
||||
@WebServlet("/archive/*")
|
||||
public class FileServlet extends AbstractFileServlet
|
||||
{
|
||||
private String root;
|
||||
|
||||
@Inject
|
||||
@DefaultConfiguration
|
||||
private ApplicationContext ctx;
|
||||
public FileServlet(@DefaultConfiguration ApplicationContext ctx){
|
||||
root = ctx.getRepoFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File getFile(HttpServletRequest request) throws IllegalArgumentException
|
||||
{
|
||||
return new File(ctx.getSystemProperties().getProperty("RepoFolder"), request.getPathInfo().substring(1));
|
||||
protected File getFile(HttpServletRequest request) throws IllegalArgumentException {
|
||||
return new File(root, request.getPathInfo().substring(1));
|
||||
}
|
||||
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
package com.oggio88.jpacrepo.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Created by walter on 06/06/15.
|
||||
*/
|
||||
public class Utility
|
||||
{
|
||||
|
||||
public static String getTemplate(String filename)
|
||||
{
|
||||
return new String(readResource("/template/" + filename));
|
||||
}
|
||||
|
||||
public static byte[] readResource(String resourcePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream is = Utility.class.getClassLoader().getResourceAsStream(resourcePath);
|
||||
byte[] res = new byte[is.available()];
|
||||
if(is.read(res,0, res.length)!= res.length)
|
||||
{
|
||||
throw new IOException("Uncompleted read");
|
||||
}
|
||||
is.close();
|
||||
return res;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
21
src/main/resources-template/persistence.xml
Normal file
21
src/main/resources-template/persistence.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
|
||||
version="2.1">
|
||||
|
||||
<persistence-unit name="jpacrepo_pu" transaction-type="JTA">
|
||||
<jta-data-source>${dataSourceJNDI}</jta-data-source>
|
||||
<properties>
|
||||
<property name="javax.persistence.schema-generation.database.action" value="${dataBaseAction}"/>
|
||||
<property name="javax.persistence.schema-generation.create-source" value="script-then-metadata"/>
|
||||
<property name="javax.persistence.schema-generation.create-script-source"
|
||||
value="META-INF/sql/CreateSchema.sql"/>
|
||||
<property name="javax.persistence.schema-generation.drop-source" value="metadata-then-script"/>
|
||||
<property name="javax.persistence.schema-generation.drop-script-source"
|
||||
value="META-INF/sql/DropSchema.sql"/>
|
||||
<property name="eclipselink.logging.level" value="INFO"/>
|
||||
<property name="hibernate.default_schema" value="jpacrepo"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
|
||||
version="2.1">
|
||||
|
||||
<persistence-unit name="jpacrepo_pu" transaction-type="JTA">
|
||||
<jta-data-source>java:/PostgresDS</jta-data-source>
|
||||
<properties>
|
||||
<!--<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>-->
|
||||
<property name="javax.persistence.schema-generation.database.action" value="none"/>
|
||||
<!--<property name="javax.persistence.schema-generation.database.action" value="create"/>-->
|
||||
<property name="eclipselink.logging.level" value="INFO"/>
|
||||
<property name="hibernate.default_schema" value="jpacrepo"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
1
src/main/resources/META-INF/sql/CreateSchema.sql
Normal file
1
src/main/resources/META-INF/sql/CreateSchema.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SCHEMA IF NOT EXISTS jpacrepo;
|
Reference in New Issue
Block a user