uniti front-end e back-end in un unico war
This commit is contained in:
17
build.gradle
17
build.gradle
@@ -26,6 +26,11 @@ dependencies {
|
||||
compile 'javax:javaee-api:7.0'
|
||||
compile 'commons-io:commons-io:2.4'
|
||||
compile 'commons-codec:commons-codec:1.10'
|
||||
compile 'eu.webtoolkit:jwt:3.3.4'
|
||||
compile 'org.projectlombok:lombok:1.16.4'
|
||||
compile 'commons-fileupload:commons-fileupload:1.3.1'
|
||||
|
||||
|
||||
testCompile 'com.thoughtworks.xstream:xstream:1.4.8'
|
||||
testCompile 'org.jboss.resteasy:resteasy-jaxrs:3.0.11.Final'
|
||||
testCompile 'org.jboss.resteasy:resteasy-client:3.0.11.Final'
|
||||
@@ -37,7 +42,17 @@ dependencies {
|
||||
}
|
||||
|
||||
task deployWildfly(dependsOn: 'war') << {
|
||||
'/opt/wildfly/bin/jboss-cli.sh --connect --user=admin --password=qwerty --command="deploy build/libs/jpacrepo-1.0.war --force"'.execute().waitFor()
|
||||
def username = 'admin', password = '123456'
|
||||
def sout = new StringBuffer(), serr = new StringBuffer()
|
||||
def cmd = sprintf('/opt/wildfly/bin/jboss-cli.sh --connect --user=%s --password=%s --command="deploy %s --force"', username, password, tasks['war'].archivePath)
|
||||
def proc = cmd.execute()
|
||||
proc.consumeProcessOutput(sout, serr)
|
||||
proc.waitFor()
|
||||
if(proc.exitValue() != 0)
|
||||
{
|
||||
println "$serr"
|
||||
throw new RuntimeException("Error occurred during deployment")
|
||||
}
|
||||
}
|
||||
|
||||
// client.jar
|
||||
|
@@ -55,5 +55,7 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" exported="" name="Gradle: eu.webtoolkit:jwt:3.3.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="Gradle: org.projectlombok:lombok:1.16.4" level="project" />
|
||||
</component>
|
||||
</module>
|
@@ -1,8 +1,12 @@
|
||||
package org.jpacrepo.context;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jpacrepo.model.PkgData;
|
||||
import org.jpacrepo.service.PacmanService;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Qualifier;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -28,6 +32,9 @@ public class ApplicationContext
|
||||
|
||||
private String repoFolder;
|
||||
|
||||
@Getter @Setter
|
||||
private PacmanService pacmanService;
|
||||
|
||||
public ApplicationContext(String propertyFile)
|
||||
{
|
||||
systemProperties = new Properties();
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package org.jpacrepo.context;
|
||||
|
||||
import org.jpacrepo.service.PacmanService;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
/**
|
||||
@@ -9,10 +12,15 @@ import javax.enterprise.inject.Produces;
|
||||
|
||||
public class ContextProducer
|
||||
{
|
||||
@EJB
|
||||
PacmanService service;
|
||||
|
||||
@Produces
|
||||
@DefaultConfiguration
|
||||
public ApplicationContext produce()
|
||||
{
|
||||
return new ApplicationContext("/etc/jpacrepo/server.properties");
|
||||
ApplicationContext ctx = new ApplicationContext("/etc/jpacrepo/server.properties");
|
||||
ctx.setPacmanService(service);
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
218
src/main/java/org/jpacrepo/frontend/component/JPacRepoApp.java
Normal file
218
src/main/java/org/jpacrepo/frontend/component/JPacRepoApp.java
Normal file
@@ -0,0 +1,218 @@
|
||||
package org.jpacrepo.frontend.component;
|
||||
|
||||
/**
|
||||
* Created by walter on 06/06/15.
|
||||
*/
|
||||
|
||||
|
||||
import eu.webtoolkit.jwt.*;
|
||||
import org.jpacrepo.context.ApplicationContext;
|
||||
import org.jpacrepo.model.PkgName;
|
||||
import org.jpacrepo.util.Utility;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by walter on 03/01/15.
|
||||
*/
|
||||
public class JPacRepoApp extends WApplication
|
||||
{
|
||||
private ApplicationContext ctx;
|
||||
private PackageTable table;
|
||||
private WPushButton searchButton;
|
||||
private WMenu pageMenu;
|
||||
private WMenu pagerMenu;
|
||||
private WComboBox pageCombo;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private WSuggestionPopup nameSuggestion, versionSuggestion, archSuggestion;
|
||||
|
||||
private int pageSize = 10;
|
||||
|
||||
private WLineEdit packageNameEdit, packageVersionEdit, packageArchEdit;
|
||||
|
||||
public JPacRepoApp(WEnvironment env, ApplicationContext ctx)
|
||||
{
|
||||
super(env);
|
||||
this.ctx = ctx;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
WBootstrapTheme theme = new WBootstrapTheme();
|
||||
theme.setVersion(WBootstrapTheme.Version.Version3);
|
||||
setTheme(theme);
|
||||
useStyleSheet(new WLink(WApplication.getRelativeResourcesUrl() + "/themes/bootstrap/3/bootstrap-theme.min.css"));
|
||||
useStyleSheet(new WLink("css/jpacrepo-web.css"));
|
||||
// useStyleSheet(new WLink("css/everywidget.css"));
|
||||
createView();
|
||||
}
|
||||
|
||||
public void createView()
|
||||
{
|
||||
WTemplate jumbotron = new WTemplate(Utility.getTemplate("jumbotron.html"));
|
||||
packageArchEdit = new WLineEdit();
|
||||
packageArchEdit.setWidth(new WLength("100%"));
|
||||
packageNameEdit = new WLineEdit();
|
||||
packageNameEdit.setWidth(new WLength("100%"));
|
||||
packageVersionEdit = new WLineEdit();
|
||||
packageVersionEdit.setWidth(new WLength("100%"));
|
||||
searchButton = new WPushButton("Search");
|
||||
pageCombo = new WComboBox();
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
pageCombo.addItem(Integer.toString(i * 10));
|
||||
}
|
||||
|
||||
|
||||
searchButton.clicked().addListener(this, () ->
|
||||
{
|
||||
pageSize = Integer.parseInt(pageCombo.getCurrentText().toString());
|
||||
while (pageMenu.getCount() > 0)
|
||||
{
|
||||
pageMenu.removeItem(pageMenu.itemAt(0));
|
||||
}
|
||||
while (pagerMenu.getCount() > 0)
|
||||
{
|
||||
pagerMenu.removeItem(pagerMenu.itemAt(0));
|
||||
}
|
||||
|
||||
long resultNumber = ctx.getPacmanService().countResults(packageNameEdit.getDisplayText(), packageVersionEdit.getDisplayText(), packageArchEdit.getDisplayText());
|
||||
if (resultNumber < pageSize)
|
||||
{
|
||||
table.showPackages(ctx.getPacmanService().searchPackage(packageNameEdit.getDisplayText(), packageVersionEdit.getDisplayText(), packageArchEdit.getDisplayText(), -1, -1));
|
||||
}
|
||||
else
|
||||
{
|
||||
int remaining = (int) resultNumber;
|
||||
int i = 1;
|
||||
while (remaining > 0)
|
||||
{
|
||||
final int logicalPageNumber = i - 1;
|
||||
WMenuItem menuItem = new WMenuItem(Integer.toString(i++));
|
||||
pageMenu.addItem(menuItem);
|
||||
menuItem.clicked().addListener(this, () ->
|
||||
{
|
||||
table.showPackages(ctx.getPacmanService().searchPackage(packageNameEdit.getText(), packageVersionEdit.getText(), packageArchEdit.getText(), logicalPageNumber, pageSize));
|
||||
});
|
||||
remaining -= pageSize;
|
||||
}
|
||||
pageMenu.select(0);
|
||||
|
||||
WMenuItem previousItem = new WMenuItem("Previous"), nextItem = new WMenuItem("Next");
|
||||
previousItem.setStyleClass("previous");
|
||||
nextItem.setStyleClass("next");
|
||||
|
||||
previousItem.clicked().addListener(this, () ->
|
||||
{
|
||||
int newIndex = pageMenu.getCurrentIndex() - 1;
|
||||
if(newIndex>=0)
|
||||
{
|
||||
pageMenu.select(newIndex);
|
||||
pageMenu.itemAt(newIndex).clicked().trigger(new WMouseEvent());
|
||||
}
|
||||
});
|
||||
|
||||
nextItem.clicked().addListener(this, () ->
|
||||
{
|
||||
int newIndex = pageMenu.getCurrentIndex() + 1;
|
||||
if(newIndex<pageMenu.getCount())
|
||||
{
|
||||
pageMenu.select(newIndex);
|
||||
pageMenu.itemAt(newIndex).clicked().trigger(new WMouseEvent());
|
||||
}
|
||||
});
|
||||
pagerMenu.addItem(previousItem);
|
||||
pagerMenu.addItem(nextItem);
|
||||
|
||||
table.showPackages(ctx.getPacmanService().searchPackage(packageNameEdit.getText(), packageVersionEdit.getText(), packageArchEdit.getText(), 0, pageSize));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
table = new PackageTable();
|
||||
WTemplate inputTemplate = new WTemplate(Utility.getTemplate("package-search-form.html"));
|
||||
inputTemplate.bindWidget("nameInput", packageNameEdit);
|
||||
inputTemplate.bindWidget("versionInput", packageVersionEdit);
|
||||
inputTemplate.bindWidget("archInput", packageArchEdit);
|
||||
inputTemplate.bindWidget("searchButton", searchButton);
|
||||
inputTemplate.bindWidget("pageInput", pageCombo);
|
||||
|
||||
WContainerWidget res = new WContainerWidget();
|
||||
|
||||
List<PkgName> nameList = ctx.getPacmanService().listProperty("name", new HashMap<>(), PkgName.class);
|
||||
List<String> nameTxtList = new ArrayList<>();
|
||||
nameList.forEach((p) -> nameTxtList.add(p.id));
|
||||
nameSuggestion = getSuggestionPopup(nameTxtList, res, packageNameEdit);
|
||||
nameSuggestion.setFilterLength(3);
|
||||
nameSuggestion.setMaximumSize(WLength.Auto, new WLength("70%"));
|
||||
|
||||
versionSuggestion = getSuggestionPopup(new ArrayList<>(), res, packageVersionEdit);
|
||||
versionSuggestion.setMaximumSize(WLength.Auto, new WLength("70%"));
|
||||
|
||||
packageNameEdit.blurred().addListener(this, () ->
|
||||
{
|
||||
if(!packageNameEdit.getDisplayText().equals(lastName))
|
||||
{
|
||||
lastName = packageNameEdit.getDisplayText();
|
||||
Map<String, String> predicateMap = new HashMap<>();
|
||||
predicateMap.put("name", packageNameEdit.getDisplayText());
|
||||
List<String> versions = ctx.getPacmanService().listProperty("version", predicateMap, String.class);
|
||||
|
||||
versionSuggestion.getModel().removeRows(0, versionSuggestion.getModel().getRowCount());
|
||||
versions.forEach((e) -> versionSuggestion.addSuggestion(e));
|
||||
packageVersionEdit.setText("");
|
||||
packageArchEdit.setText("");
|
||||
}
|
||||
});
|
||||
|
||||
List<String> archs = ctx.getPacmanService().listProperty("arch", new HashMap<>(), String.class);
|
||||
archSuggestion = getSuggestionPopup(archs, res, packageArchEdit);
|
||||
|
||||
res.addWidget(jumbotron);
|
||||
res.addWidget(inputTemplate);
|
||||
WContainerWidget containerWidget = new WContainerWidget();
|
||||
containerWidget.addWidget(table);
|
||||
containerWidget.setStyleClass("row");
|
||||
res.addWidget(containerWidget);
|
||||
res.setStyleClass("container main-container");
|
||||
|
||||
pageMenu = new WMenu();
|
||||
pageMenu.setStyleClass("pagination");
|
||||
res.addWidget(pageMenu);
|
||||
|
||||
pagerMenu = new WMenu();
|
||||
pageCombo.setWidth(new WLength("100%"));
|
||||
pagerMenu.setStyleClass("pager");
|
||||
res.addWidget(pagerMenu);
|
||||
|
||||
getRoot().addWidget(res);
|
||||
}
|
||||
|
||||
WSuggestionPopup getSuggestionPopup(List<String> suggestions, WWidget parent, WFormWidget linkedFormWidget)
|
||||
{
|
||||
WSuggestionPopup.Options contactOptions = new WSuggestionPopup.Options();
|
||||
contactOptions.highlightBeginTag = "<u><strong>";
|
||||
contactOptions.highlightEndTag = "</strong></u>";
|
||||
contactOptions.listSeparator = ',';
|
||||
contactOptions.whitespace = " \\n";
|
||||
contactOptions.wordSeparators = "-., \"@\\n;";
|
||||
//contactOptions.appendReplacedText = ", ";
|
||||
WSuggestionPopup popup = new WSuggestionPopup(WSuggestionPopup
|
||||
.generateMatcherJS(contactOptions), WSuggestionPopup
|
||||
.generateReplacerJS(contactOptions), parent);
|
||||
popup.forEdit(linkedFormWidget, EnumSet.of(WSuggestionPopup.PopupTrigger.Editing, WSuggestionPopup.PopupTrigger.DropDownIcon));
|
||||
List<WString> wstrings = new ArrayList<>();
|
||||
for(String suggestion :suggestions)
|
||||
{
|
||||
wstrings.add(new WString(suggestion));
|
||||
// popup.addSuggestion(suggestion);
|
||||
}
|
||||
popup.setModel(new WStringListModel(wstrings));
|
||||
return popup;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
package org.jpacrepo.frontend.component;
|
||||
|
||||
import eu.webtoolkit.jwt.*;
|
||||
import org.jpacrepo.model.PkgData;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by walter on 06/06/15.
|
||||
*/
|
||||
public class PackageTable extends WTable
|
||||
{
|
||||
public PackageTable()
|
||||
{
|
||||
toggleStyleClass("table-bordered", true);
|
||||
toggleStyleClass("table-condensed", true);
|
||||
toggleStyleClass("table-striped", true);
|
||||
|
||||
}
|
||||
|
||||
public void showPackages(List<PkgData> pkgs)
|
||||
{
|
||||
clear();
|
||||
setHeaderCount(1);
|
||||
setWidth(new WLength("100%"));
|
||||
|
||||
getElementAt(0, 0).addWidget(new WText("Name"));
|
||||
getElementAt(0, 1).addWidget(new WText("Version"));
|
||||
getElementAt(0, 2).addWidget(new WText("Arch"));
|
||||
getElementAt(0, 3).addWidget(new WText("Description"));
|
||||
getElementAt(0, 4).addWidget(new WText("Size"));
|
||||
|
||||
|
||||
for(int row =1 ; row<pkgs.size()+1; row++)
|
||||
{
|
||||
PkgData pkg = pkgs.get(row-1);
|
||||
getElementAt(row, 0).addWidget(getCellText(pkg.name.id, "text-center"));
|
||||
getElementAt(row, 1).addWidget(getCellText(pkg.version, "text-center"));
|
||||
getElementAt(row, 2).addWidget(getCellText(pkg.arch, "text-center"));
|
||||
getElementAt(row, 3).addWidget(getCellText(pkg.description, "text-center"));
|
||||
getElementAt(row, 4).addWidget(getCellText(readableFileSize(pkg.size), "text-center"));
|
||||
//WPushButton button = new WPushButton("Download");
|
||||
|
||||
WAnchor button = new WAnchor();
|
||||
button.setStyleClass("btn btn-default");
|
||||
//text.setStyleClass("glyphicon glyphicon-download-alt");
|
||||
|
||||
WImage img = new WImage("img/download.svg");
|
||||
img.setStyleClass("download-icon");
|
||||
img.setWidth(new WLength("16px"));
|
||||
button.setImage(img);
|
||||
button.setLink(new WLink(WLink.Type.Url, "rest/pkg/download/" + pkg.fileName));
|
||||
button.addStyleClass("text-center");
|
||||
WText text = new WText("Download",button);
|
||||
getElementAt(row, 5).addWidget(button);
|
||||
}
|
||||
}
|
||||
|
||||
private WText getCellText(String text, String styleClass)
|
||||
{
|
||||
WText res = new WText(text);
|
||||
res.setWidth(new WLength("100%"));
|
||||
res.setStyleClass(styleClass);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String readableFileSize(long size)
|
||||
{
|
||||
if (size <= 0) return "0";
|
||||
final String[] units = new String[]{"B", "kB", "MB", "GB", "TB"};
|
||||
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
|
||||
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package org.jpacrepo.frontend.servlet;
|
||||
|
||||
import eu.webtoolkit.jwt.WApplication;
|
||||
import eu.webtoolkit.jwt.WEnvironment;
|
||||
import eu.webtoolkit.jwt.WtServlet;
|
||||
import org.jpacrepo.context.ApplicationContext;
|
||||
import org.jpacrepo.context.DefaultConfiguration;
|
||||
import org.jpacrepo.frontend.component.JPacRepoApp;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
|
||||
/**
|
||||
* Created by walter on 06/06/15.
|
||||
*/
|
||||
|
||||
|
||||
@WebServlet(name="app.CherebaServlet", urlPatterns={"/view/*"})
|
||||
public class JPacRepoServlet extends WtServlet
|
||||
{
|
||||
@Inject
|
||||
@DefaultConfiguration
|
||||
ApplicationContext ctx;
|
||||
|
||||
private static final long serialVersionUID = 1236894561762L;
|
||||
|
||||
public JPacRepoServlet()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WApplication createApplication(WEnvironment env)
|
||||
{
|
||||
return new JPacRepoApp(env, ctx);
|
||||
}
|
||||
|
||||
}
|
37
src/main/java/org/jpacrepo/model/PkgData_.java
Normal file
37
src/main/java/org/jpacrepo/model/PkgData_.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package org.jpacrepo.model;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.annotation.Generated;
|
||||
import javax.persistence.metamodel.ListAttribute;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
import javax.persistence.metamodel.StaticMetamodel;
|
||||
|
||||
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
|
||||
@StaticMetamodel(PkgData.class)
|
||||
public abstract class PkgData_ {
|
||||
|
||||
public static volatile SingularAttribute<PkgData, String> fileName;
|
||||
public static volatile ListAttribute<PkgData, String> backup;
|
||||
public static volatile ListAttribute<PkgData, String> makeopkgopt;
|
||||
public static volatile ListAttribute<PkgData, String> depend;
|
||||
public static volatile ListAttribute<PkgData, String> replaces;
|
||||
public static volatile SingularAttribute<PkgData, Date> updTimestamp;
|
||||
public static volatile SingularAttribute<PkgData, String> description;
|
||||
public static volatile SingularAttribute<PkgData, Date> buildDate;
|
||||
public static volatile SingularAttribute<PkgData, String> version;
|
||||
public static volatile SingularAttribute<PkgData, String> packager;
|
||||
public static volatile SingularAttribute<PkgData, String> url;
|
||||
public static volatile SingularAttribute<PkgData, String> license;
|
||||
public static volatile SingularAttribute<PkgData, Long> size;
|
||||
public static volatile ListAttribute<PkgData, String> makedepend;
|
||||
public static volatile ListAttribute<PkgData, String> optdepend;
|
||||
public static volatile SingularAttribute<PkgData, String> md5sum;
|
||||
public static volatile ListAttribute<PkgData, String> provides;
|
||||
public static volatile SingularAttribute<PkgData, PkgName> name;
|
||||
public static volatile SingularAttribute<PkgData, Integer> id;
|
||||
public static volatile SingularAttribute<PkgData, String> arch;
|
||||
public static volatile SingularAttribute<PkgData, String> base;
|
||||
public static volatile ListAttribute<PkgData, String> conflict;
|
||||
|
||||
}
|
||||
|
14
src/main/java/org/jpacrepo/model/PkgName_.java
Normal file
14
src/main/java/org/jpacrepo/model/PkgName_.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.jpacrepo.model;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
import javax.persistence.metamodel.StaticMetamodel;
|
||||
|
||||
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
|
||||
@StaticMetamodel(PkgName.class)
|
||||
public abstract class PkgName_ {
|
||||
|
||||
public static volatile SingularAttribute<PkgName, String> id;
|
||||
|
||||
}
|
||||
|
@@ -1,14 +1,24 @@
|
||||
package org.jpacrepo.service;
|
||||
|
||||
import javax.ejb.Remote;
|
||||
import org.jpacrepo.model.PkgData;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by walter on 28/03/15.
|
||||
*/
|
||||
|
||||
@Remote
|
||||
@Local
|
||||
public interface PacmanService
|
||||
{
|
||||
public void deletePackage(String filename) throws Exception;
|
||||
|
||||
public long countResults(String name, String version, String arch);
|
||||
|
||||
public 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);
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,10 @@ import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -238,6 +242,135 @@ public class PacmanServiceEJB implements PacmanService
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countResults(String name, String version, String arch)
|
||||
{
|
||||
CriteriaBuilder builder;
|
||||
CriteriaQuery<Long> criteriaQuery;
|
||||
Root<PkgData> entity;
|
||||
|
||||
builder = em.getCriteriaBuilder();
|
||||
criteriaQuery = builder.createQuery(Long.class);
|
||||
entity = criteriaQuery.from(PkgData.class);
|
||||
Predicate finalPredicate=null, p;
|
||||
|
||||
if(name != null && !name.isEmpty())
|
||||
{
|
||||
p = builder.equal(entity.get("name").get("id"), name);
|
||||
finalPredicate = p;
|
||||
}
|
||||
if(version != null && !version.isEmpty())
|
||||
{
|
||||
p=builder.equal(entity.get("version"), version);
|
||||
finalPredicate = finalPredicate != null ? builder.and(finalPredicate, p) : p;
|
||||
}
|
||||
if(arch != null && !arch.isEmpty())
|
||||
{
|
||||
p=builder.equal(entity.get("arch"), arch);
|
||||
finalPredicate = finalPredicate != null ? builder.and(finalPredicate, p) : p;
|
||||
}
|
||||
|
||||
if(finalPredicate != null)
|
||||
{
|
||||
criteriaQuery.select(builder.count(entity)).where(finalPredicate);
|
||||
}
|
||||
else
|
||||
{
|
||||
criteriaQuery.select(builder.count(entity));
|
||||
}
|
||||
TypedQuery<Long> query = em.createQuery(criteriaQuery);
|
||||
return em.createQuery(criteriaQuery).getSingleResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public<T> List<T> listProperty(String property, Map<String,String> equalityConditions, Class<T> cls)
|
||||
{
|
||||
CriteriaBuilder builder = em.getCriteriaBuilder();
|
||||
CriteriaQuery<T> criteriaQuery = builder.createQuery(cls);
|
||||
Root<PkgData> entity = criteriaQuery.from(PkgData.class);
|
||||
|
||||
Predicate finalPredicate=null, p;
|
||||
String key = equalityConditions.get("name");
|
||||
if(key != null && !key.isEmpty())
|
||||
{
|
||||
p = builder.equal(entity.get("name").get("id"), key);
|
||||
finalPredicate = p;
|
||||
}
|
||||
|
||||
key = equalityConditions.get("version");
|
||||
if(key != null && !key.isEmpty())
|
||||
{
|
||||
p = builder.equal(entity.get("version"), key);
|
||||
finalPredicate = p;
|
||||
}
|
||||
|
||||
key = equalityConditions.get("arch");
|
||||
if(key != null && !key.isEmpty())
|
||||
{
|
||||
p = builder.equal(entity.get("arch"), key);
|
||||
finalPredicate = p;
|
||||
}
|
||||
|
||||
if(finalPredicate != null)
|
||||
{
|
||||
criteriaQuery.select(entity.get(property)).distinct(true).where(finalPredicate);
|
||||
}
|
||||
else
|
||||
{
|
||||
criteriaQuery.select(entity.get(property)).distinct(true);
|
||||
}
|
||||
return em.createQuery(criteriaQuery).getResultList();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<PkgData> searchPackage(String name, String version, String arch, int pageNumber, int pageSize)
|
||||
{
|
||||
CriteriaBuilder builder;
|
||||
CriteriaQuery<PkgData> criteriaQuery;
|
||||
Root<PkgData> entity;
|
||||
|
||||
builder = em.getCriteriaBuilder();
|
||||
criteriaQuery = builder.createQuery(PkgData.class);
|
||||
entity = criteriaQuery.from(PkgData.class);
|
||||
Predicate finalPredicate=null, p;
|
||||
|
||||
if(name != null && !name.isEmpty())
|
||||
{
|
||||
p = builder.equal(entity.get("name").get("id"), name);
|
||||
finalPredicate = p;
|
||||
}
|
||||
if(version != null && !version.isEmpty())
|
||||
{
|
||||
p=builder.equal(entity.get("version"), version);
|
||||
finalPredicate = finalPredicate != null ? builder.and(finalPredicate, p) : p;
|
||||
}
|
||||
if(arch != null && !arch.isEmpty())
|
||||
{
|
||||
p=builder.equal(entity.get("arch"), arch);
|
||||
finalPredicate = finalPredicate != null ? builder.and(finalPredicate, p) : p;
|
||||
}
|
||||
|
||||
if(finalPredicate != null)
|
||||
{
|
||||
criteriaQuery.select(entity).where(finalPredicate).orderBy(builder.asc(entity.get("fileName")));
|
||||
}
|
||||
else
|
||||
{
|
||||
criteriaQuery.select(entity).orderBy(builder.asc(entity.get("fileName")));
|
||||
}
|
||||
TypedQuery<PkgData> query = em.createQuery(criteriaQuery);
|
||||
if(pageNumber>=0)
|
||||
{
|
||||
query.setFirstResult(pageNumber*pageSize);
|
||||
}
|
||||
if(pageSize>0)
|
||||
{
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
return query.getResultList();
|
||||
|
||||
}
|
||||
}
|
35
src/main/java/org/jpacrepo/util/Utility.java
Normal file
35
src/main/java/org/jpacrepo/util/Utility.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package org.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);
|
||||
}
|
||||
}
|
||||
}
|
17
src/main/resources/WEB-INF/web.xml
Normal file
17
src/main/resources/WEB-INF/web.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||
version="3.1">
|
||||
|
||||
<listener>
|
||||
<listener-class>eu.webtoolkit.jwt.ServletInit</listener-class>
|
||||
</listener>
|
||||
|
||||
<display-name>jpacrepo</display-name>
|
||||
<description>jpacrepo</description>
|
||||
|
||||
<!--<session-config>-->
|
||||
<!--<tracking-mode>URL</tracking-mode>-->
|
||||
<!--</session-config>-->
|
||||
|
||||
</web-app>
|
4
src/main/resources/template/jumbotron.html
Normal file
4
src/main/resources/template/jumbotron.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<div class="jumbotron text-center">
|
||||
<h1>JPacRepo</h1>
|
||||
<p>The personal archlinux package repository</p>
|
||||
</div>
|
46
src/main/resources/template/package-search-form.html
Normal file
46
src/main/resources/template/package-search-form.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<div class="input-control search-input">
|
||||
<div class="row">
|
||||
<div class="col-sm-5">
|
||||
<label>
|
||||
Name:
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label>
|
||||
Version:
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label>
|
||||
Arch:
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label>
|
||||
Page size:
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<form class="form-inline">
|
||||
<div class="form-group col-sm-5">
|
||||
${nameInput}
|
||||
</div>
|
||||
<div class="form-group col-sm-2">
|
||||
${versionInput}
|
||||
</div>
|
||||
<div class="form-group col-sm-2">
|
||||
${archInput}
|
||||
</div>
|
||||
<div class="form-group col-sm-2">
|
||||
${pageInput}
|
||||
</div>
|
||||
<div class="form-group col-sm-1">
|
||||
${searchButton}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
28
src/main/webapp/css/jpacrepo-web.css
Normal file
28
src/main/webapp/css/jpacrepo-web.css
Normal file
@@ -0,0 +1,28 @@
|
||||
div.input-control {
|
||||
margin-bottom: 2%;
|
||||
background-color: #ccc;
|
||||
padding: 1% 2%;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
html body.Wt-ltr div.Wt-domRoot div div.container div.row table.table-bordered.table-condensed.table-striped tbody tr td {
|
||||
text-align: center;
|
||||
}
|
||||
html body.Wt-ltr div.Wt-domRoot div div.container div.row table.table-bordered.table-condensed.table-striped thead tr th {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.search-input form.form-inline div.form-group
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.container.main-container
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
td a img.download-icon
|
||||
{
|
||||
margin-right: 5px;
|
||||
}
|
BIN
src/main/webapp/img/download.png
Normal file
BIN
src/main/webapp/img/download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
15
src/main/webapp/img/download.svg
Normal file
15
src/main/webapp/img/download.svg
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="512px" height="526.05px" viewBox="0.328 0 512 526.05" enable-background="new 0.328 0 512 526.05" xml:space="preserve">
|
||||
<g>
|
||||
<path d="M482.842,308.102c-16.287,0-29.486,13.194-29.486,29.486v129.488H59.302V337.588c0-16.292-13.188-29.486-29.486-29.486
|
||||
c-16.287,0-29.487,13.194-29.487,29.486v158.975c0,16.287,13.2,29.487,29.487,29.487h453.026c16.287,0,29.487-13.2,29.487-29.487
|
||||
V337.588C512.329,321.296,499.129,308.102,482.842,308.102z"/>
|
||||
<path d="M235.473,374.613c5.534,5.529,13.032,8.639,20.854,8.639c7.818,0,15.316-3.093,20.845-8.639l118.903-118.905
|
||||
c11.518-11.51,11.518-30.181,0-41.693c-11.507-11.519-30.189-11.519-41.696,0l-68.568,68.568V29.487
|
||||
C285.81,13.197,272.611,0,256.327,0c-16.287,0-29.486,13.197-29.486,29.487v253.09l-68.551-68.557
|
||||
c-11.519-11.519-30.195-11.513-41.702-0.006c-11.507,11.519-11.507,30.189-0.006,41.699L235.473,374.613z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.2 KiB |
Reference in New Issue
Block a user