#6 Added new entity Url

This commit is contained in:
Robert Vokac 2023-05-13 16:57:27 +02:00
parent 797337572b
commit a3645fe758
Signed by: robertvokac
GPG Key ID: 693D30BEE3329055
19 changed files with 1354 additions and 63 deletions

View File

@ -38,7 +38,6 @@ public class Item {
private String label;
private String disambiguation;
private String description;
private String url;
private String attributes;
private String aliases;
private Boolean entryPointItem;

View File

@ -0,0 +1,44 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Nanodata.
// Copyright (C) 2023-2023 the original author or authors.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// of the License only.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package org.nanoboot.nanodata.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;
/**
*
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
* @since 0.0.0
*/
@Data
@AllArgsConstructor
@ToString
public class Url {
private String id;
private String url;
private String name;
private String itemId;
private Boolean official;
private String createdAt;
}

View File

@ -0,0 +1,37 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Nanodata.
// Copyright (C) 2023-2023 the original author or authors.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// of the License only.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package org.nanoboot.nanodata.persistence.api;
import java.util.List;
import org.nanoboot.nanodata.entity.Url;
/**
*
* @author robertvokac
*/
public interface UrlRepo {
List<Url> list(int pageNumber, int pageSize, String urlLike, TextPosition textPosition, String itemId);
String create(Url url);
Url read(String id);
void update(Url url);
void delete(String id);
}

View File

@ -112,7 +112,6 @@ public class ItemRepoImplSqlite implements ItemRepo {
rs.getString(ItemTable.LABEL),
rs.getString(ItemTable.DISAMBIGUATION),
rs.getString(ItemTable.DESCRIPTION),
rs.getString(ItemTable.URL),
rs.getString(ItemTable.ATTRIBUTES),
rs.getString(ItemTable.ALIASES),
rs.getInt(ItemTable.ENTRY_POINT_ITEM) != 0,
@ -128,9 +127,6 @@ public class ItemRepoImplSqlite implements ItemRepo {
if(item.getDisambiguation() == null) {
item.setDisambiguation("");
}
if(item.getUrl() != null && item.getUrl().endsWith("/")) {
item.setUrl(item.getUrl().substring(0, item.getUrl().length() -1));
}
StringBuilder sb = new StringBuilder();
sb
.append("INSERT INTO ")
@ -141,7 +137,6 @@ public class ItemRepoImplSqlite implements ItemRepo {
.append(ItemTable.LABEL).append(",")
.append(ItemTable.DISAMBIGUATION).append(",")
.append(ItemTable.DESCRIPTION).append(",")
.append(ItemTable.URL).append(",")
//
.append(ItemTable.ATTRIBUTES).append(",")
.append(ItemTable.ALIASES).append(",")
@ -149,7 +144,7 @@ public class ItemRepoImplSqlite implements ItemRepo {
.append(ItemTable.CREATED_AT);
sb.append(")")
.append(" VALUES (?, ?,?,?, ?, ?,?,?,?)");
.append(" VALUES (?, ?,?, ?, ?,?,?,?)");
String sql = sb.toString();
System.err.println(sql);
@ -161,7 +156,6 @@ public class ItemRepoImplSqlite implements ItemRepo {
stmt.setString(++i, item.getLabel());
stmt.setString(++i, item.getDisambiguation());
stmt.setString(++i, item.getDescription());
stmt.setString(++i, item.getUrl());
//
stmt.setString(++i, item.getAttributes());
stmt.setString(++i, item.getAliases());
@ -233,9 +227,6 @@ public class ItemRepoImplSqlite implements ItemRepo {
item.setDisambiguation("");
}
if(item.getUrl() != null && item.getUrl().endsWith("/")) {
item.setUrl(item.getUrl().substring(0, item.getUrl().length() -1));
}
StringBuilder sb = new StringBuilder();
sb
.append("UPDATE ")
@ -244,7 +235,6 @@ public class ItemRepoImplSqlite implements ItemRepo {
.append(ItemTable.LABEL).append("=?, ")
.append(ItemTable.DISAMBIGUATION).append("=?, ")
.append(ItemTable.DESCRIPTION).append("=?, ")
.append(ItemTable.URL).append("=?, ")
//
.append(ItemTable.ATTRIBUTES).append("=?, ")
.append(ItemTable.ALIASES).append("=?, ")
@ -259,7 +249,6 @@ public class ItemRepoImplSqlite implements ItemRepo {
stmt.setString(++i, item.getLabel());
stmt.setString(++i, item.getDisambiguation());
stmt.setString(++i, item.getDescription());
stmt.setString(++i, item.getUrl());
//
stmt.setString(++i, item.getAttributes());
stmt.setString(++i, item.getAliases());

View File

@ -29,7 +29,6 @@ public class ItemTable {
public static final String LABEL = "LABEL";
public static final String DISAMBIGUATION = "DISAMBIGUATION";
public static final String DESCRIPTION = "DESCRIPTION";
public static final String URL = "URL";
public static final String ATTRIBUTES = "ATTRIBUTES";
//
public static final String ALIASES = "ALIASES";

View File

@ -0,0 +1,316 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Nanodata.
// Copyright (C) 2023-2023 the original author or authors.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// of the License only.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package org.nanoboot.nanodata.persistence.impl.sqlite;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import lombok.Setter;
import org.nanoboot.nanodata.entity.Url;
import org.nanoboot.nanodata.persistence.api.UrlRepo;
import org.nanoboot.nanodata.persistence.api.TextPosition;
import static org.nanoboot.nanodata.persistence.api.TextPosition.DOES_NOT_MATTER;
import static org.nanoboot.nanodata.persistence.api.TextPosition.LEFT;
import static org.nanoboot.nanodata.persistence.api.TextPosition.RIGHT;
import org.nanoboot.powerframework.time.moment.UniversalDateTime;
/**
*
* @author robertvokac
*/
public class UrlRepoImplSqlite implements UrlRepo {
@Setter
private SqliteConnectionFactory sqliteConnectionFactory;
@Override
public List<Url> list(int pageNumber, int pageSize, String urlLike, TextPosition textPosition, String itemId) {
List<Url> result = new ArrayList<>();
StringBuilder sb = new StringBuilder();
sb
.append("SELECT * FROM ")
.append(UrlTable.TABLE_NAME);
sb.append(" WHERE 1=1");
if (urlLike != null) {
sb.append(" AND ").append(UrlTable.NAME);
switch (textPosition) {
case LEFT:
sb.append(" LIKE ? || '%'");
break;
case DOES_NOT_MATTER:
sb.append(" LIKE '%' || ? || '%'");
break;
case RIGHT:
sb.append(" LIKE '%' || ?");
break;
default:
throw new RuntimeException("Unsupported TextPosition: " + textPosition);
}
}
if (itemId != null) {
sb.append(" AND ").append(UrlTable.ITEM_ID).append("=? ");
}
{
sb.append(" LIMIT ? OFFSET ? ");
}
String sql = sb.toString();
System.err.println(sql);
int i = 0;
ResultSet rs = null;
try (
Connection connection = sqliteConnectionFactory.createConnection(); PreparedStatement stmt = connection.prepareStatement(sql);) {
if (urlLike != null) {
stmt.setString(++i, urlLike);
}
if (itemId != null) {
stmt.setString(++i, itemId);
}
stmt.setInt(++i, pageSize);
stmt.setInt(++i, (pageNumber - 1) * pageSize);
System.err.println(stmt.toString());
rs = stmt.executeQuery();
while (rs.next()) {
result.add(extractUrlFromResultSet(rs));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e);
} catch (ClassNotFoundException ex) {
Logger.getLogger(UrlRepoImplSqlite.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException ex) {
Logger.getLogger(UrlRepoImplSqlite.class.getName()).log(Level.SEVERE, null, ex);
}
}
return result;
}
private static Url extractUrlFromResultSet(final ResultSet rs) throws SQLException {
return new Url(
rs.getString(UrlTable.ID),
rs.getString(UrlTable.URL),
rs.getString(UrlTable.NAME),
rs.getString(UrlTable.ITEM_ID),
rs.getInt(UrlTable.OFFICIAL) != 0,
rs.getString(UrlTable.CREATED_AT)
);
}
@Override
public String create(Url url) {
if (url.getId() == null) {
url.setId(UUID.randomUUID().toString());
}
if (url.getOfficial() == null) {
url.setOfficial(false);
}
if (url.getName() == null) {
url.setName("");
}
if (url.getUrl() != null) {
url.setUrl(url.getUrl().trim());
}
if (url.getUrl() != null && url.getUrl().endsWith("/")) {
url.setUrl(url.getUrl().substring(0, url.getUrl().length() - 1));
}
StringBuilder sb = new StringBuilder();
sb
.append("INSERT INTO ")
.append(UrlTable.TABLE_NAME)
.append("(")
.append(UrlTable.ID).append(",")
//
.append(UrlTable.URL).append(",")
.append(UrlTable.NAME).append(",")
.append(UrlTable.ITEM_ID).append(",")
.append(UrlTable.OFFICIAL).append(",")
.append(UrlTable.CREATED_AT);
sb.append(")")
.append(" VALUES (?,?,?, ?,?,?)");
String sql = sb.toString();
System.err.println(sql);
try (
Connection connection = sqliteConnectionFactory.createConnection(); PreparedStatement stmt = connection.prepareStatement(sql);) {
int i = 0;
stmt.setString(++i, url.getId());
stmt.setString(++i, url.getUrl());
stmt.setString(++i, url.getName());
//
stmt.setString(++i, url.getItemId());
stmt.setInt(++i, url.getOfficial() ? 1 : 0);
stmt.setString(++i, UniversalDateTime.now().toString());
//
stmt.execute();
System.out.println(stmt.toString());
return url.getId();
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e);
} catch (ClassNotFoundException ex) {
Logger.getLogger(UrlRepoImplSqlite.class.getName()).log(Level.SEVERE, null, ex);
}
System.err.println("Error.");
return "";
}
@Override
public Url read(String id) {
if (id == null) {
throw new RuntimeException("id is null");
}
StringBuilder sb = new StringBuilder();
sb
.append("SELECT * FROM ")
.append(UrlTable.TABLE_NAME)
.append(" WHERE ")
.append(UrlTable.ID)
.append("=?");
String sql = sb.toString();
int i = 0;
ResultSet rs = null;
try (
Connection connection = sqliteConnectionFactory.createConnection(); PreparedStatement stmt = connection.prepareStatement(sql);) {
stmt.setString(++i, id);
rs = stmt.executeQuery();
while (rs.next()) {
return extractUrlFromResultSet(rs);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e);
} catch (ClassNotFoundException ex) {
Logger.getLogger(UrlRepoImplSqlite.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException ex) {
Logger.getLogger(UrlRepoImplSqlite.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
@Override
public void update(Url url) {
if (url.getOfficial() == null) {
url.setOfficial(false);
}
if (url.getName() == null) {
url.setName("");
}
if (url.getUrl() != null) {
url.setUrl(url.getUrl().trim());
}
if (url.getUrl() != null && url.getUrl().endsWith("/")) {
url.setUrl(url.getUrl().substring(0, url.getUrl().length() - 1));
}
StringBuilder sb = new StringBuilder();
sb
.append("UPDATE ")
.append(UrlTable.TABLE_NAME)
.append(" SET ")
.append(UrlTable.URL).append("=?, ")
.append(UrlTable.NAME).append("=?, ")
.append(UrlTable.ITEM_ID).append("=?, ")
.append(UrlTable.OFFICIAL).append("=? ")
.append(" WHERE ").append(ItemTable.ID).append("=?");
String sql = sb.toString();
System.err.println(sql);
try (
Connection connection = sqliteConnectionFactory.createConnection(); PreparedStatement stmt = connection.prepareStatement(sql);) {
int i = 0;
stmt.setString(++i, url.getUrl());
stmt.setString(++i, url.getName());
stmt.setString(++i, url.getItemId());
stmt.setInt(++i, url.getOfficial() ? 1 : 0);
//
stmt.setString(++i, url.getId());
System.out.println(stmt.toString());
int numberOfUpdatedRows = stmt.executeUpdate();
System.out.println("numberOfUpdatedRows=" + numberOfUpdatedRows);
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e);
} catch (ClassNotFoundException ex) {
Logger.getLogger(UrlRepoImplSqlite.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void delete(String id) {
StringBuilder sb = new StringBuilder();
sb
.append("DELETE FROM ")
.append(UrlTable.TABLE_NAME);
sb.append(" WHERE ");
sb.append(UrlTable.ID);
sb.append("=?");
String sql = sb.toString();
System.err.println("SQL::" + sql);
int i = 0;
try (
Connection connection = sqliteConnectionFactory.createConnection(); PreparedStatement stmt = connection.prepareStatement(sql);) {
stmt.setString(++i, id);
System.err.println(stmt.toString());
stmt.execute();
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException(e);
} catch (ClassNotFoundException ex) {
Logger.getLogger(StatementRepoImplSqlite.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

View File

@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Nanodata.
// Copyright (C) 2023-2023 the original author or authors.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// of the License only.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package org.nanoboot.nanodata.persistence.impl.sqlite;
/**
*
* @author robertvokac
*/
public class UrlTable {
public static final String TABLE_NAME = "URL";
public static final String ID = "ID";
public static final String URL = "URL";
public static final String NAME = "NAME";
//
public static final String ITEM_ID = "ITEM_ID";
public static final String OFFICIAL = "OFFICIAL";
public static final String CREATED_AT = "CREATED_AT";
private UrlTable() {
//Not meant to be instantiated.
}
}

View File

@ -0,0 +1,25 @@
CREATE TABLE "URL" (
"ID" TEXT,
"URL" TEXT NOT NULL,
"NAME" TEXT NOT NULL DEFAULT '',
"ITEM_ID" TEXT,
"OFFICIAL" INTEGER DEFAULT 0,
"CREATED_AT" TEXT,
UNIQUE(URL),
FOREIGN KEY("ITEM_ID") REFERENCES "ITEM"("ID"),
PRIMARY KEY("ID")
);
INSERT INTO URL (
ID,URL, NAME, ITEM_ID,OFFICIAL,CREATED_AT
)
select
lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))) AS ID,
URL,
'' AS NAME,
id as ITEM_ID,
1 AS OFFICIAL,
datetime('now')||':000' AS CREATED_AT
from item where url is not null and url<>'';
ALTER TABLE ITEM DROP COLUMN URL;

View File

@ -46,5 +46,9 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="statementRepoImplSqlite" class="org.nanoboot.nanodata.persistence.impl.sqlite.StatementRepoImplSqlite">
<property name="sqliteConnectionFactory" ref="sqliteConnectionFactory" />
</bean>
<bean id="urlRepoImplSqlite" class="org.nanoboot.nanodata.persistence.impl.sqlite.UrlRepoImplSqlite">
<property name="sqliteConnectionFactory" ref="sqliteConnectionFactory" />
</bean>
</beans>

View File

@ -75,10 +75,6 @@
<td><label for="description">Description:</label></td>
<td style="text-align:left;"><input type="text" name="description" value="" ></td>
</tr>
<tr>
<td><label for="url">Url</label></td>
<td style="text-align:left;"><input type="text" name="url" value="" ></td>
</tr>
<tr>
<td><label for="attributes">Attributes:</label></td>
<td style="text-align:left;">
@ -114,7 +110,6 @@
String param_disambiguation = request.getParameter("disambiguation");
String param_description = request.getParameter("description");
String param_url = request.getParameter("url");
String param_attributes = request.getParameter("attributes");
String param_aliases = request.getParameter("aliases");
String param_entryPointItem = request.getParameter("entryPointItem");
@ -128,9 +123,6 @@
param_description = null;
}
if (param_url != null && param_url.isEmpty()) {
param_url = null;
}
if (param_attributes != null && param_attributes.isEmpty()) {
param_attributes = null;
}
@ -147,7 +139,6 @@
param_label,
param_disambiguation,
param_description,
param_url,
param_attributes,
param_aliases,
param_entryPointItem == null ? false : param_entryPointItem.equals("1"),

View File

@ -0,0 +1,140 @@
<!--
Nanodata.
Copyright (C) 2023-2023 the original author or authors.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<%@ page session="false" %>
<%@page import="org.nanoboot.nanodata.persistence.api.UrlRepo"%>
<%@page import="org.nanoboot.nanodata.entity.Url"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<!DOCTYPE>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Nanodata - Add url</title>
<link rel="stylesheet" type="text/css" href="styles/nanodata.css">
<link rel="icon" type="image/x-icon" href="favicon.ico" sizes="32x32">
</head>
<body>
<a href="index.jsp" id="main_title">Nanodata</a></span>
<span class="nav"><a href="index.jsp">Home</a>
>> <a href="urls.jsp">Urls</a>
>> <a href="create_url.jsp" class="nav_a_current">Add Url</a></span>
<%
if (org.nanoboot.nanodata.web.misc.utils.Utils.cannotUpdate(request)) {
out.println("Access forbidden");
throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
UrlRepo urlRepo = context.getBean("urlRepoImplSqlite", UrlRepo.class);
%>
<%
String param_url = request.getParameter("url");
String param_item_id_for_form = request.getParameter("item_id");
boolean formToBeProcessed = param_url != null && !param_url.isEmpty();
%>
<% if (!formToBeProcessed) { %>
<form action="create_url.jsp" method="post">
<table>
<tr>
<td><label for="url">Url<b style="color:red;font-size:130%;">*</b>:</label></td>
<td><input type="text" name="url" value="<%=(param_url==null?"":param_url)%>"></td>
</tr>
<tr>
<td><label for="name">Name</label></td>
<td><input type="text" name="name" value=""></td>
</tr>
<tr>
<td><label for="item_id">Item id<b style="color:red;font-size:130%;">*</b></label></td>
<td style="text-align:left;"><input type="text" name="item_id" value="<%=(param_item_id_for_form==null?"":param_item_id_for_form)%>" ></td>
</tr>
<tr>
<td><label for="official">Official</label></td>
<td style="text-align:left;">
<input type="checkbox" name="official" value="1" >
</td>
</tr>
<tr>
<td><a href="urls.jsp" style="font-size:130%;background:#dddddd;border:2px solid #bbbbbb;padding:2px;text-decoration:none;">Cancel</a></td>
<td style="text-align:right;"><input type="submit" value="Add"></td>
</tr>
</table>
<b style="color:red;font-size:200%;margin-left:20px;">*</b> ...mandatory
</form>
<iframe src="items.jsp" width="800" height="800">
</iframe>
<% } else { %>
<%
String param_name = request.getParameter("name");
String param_official = request.getParameter("official");
String param_item_id = request.getParameter("item_id");
if(param_official == null) {
param_official = "0";
}
//
Url newUrl = new Url(
null,
param_url,
param_name,
param_item_id,
Boolean.valueOf(param_official.equals("1")),
null
);
String idOfUrl = urlRepo.create(newUrl);
newUrl.setId(idOfUrl);
%>
<p style="margin-left:20px;font-size:130%;">Created new url with id <%=newUrl.getId()%>:<br><br>
<a href="read_url.jsp?id=<%=newUrl.getId()%>"><%=newUrl.getId()%></a>
</p>
<% }%>
<div id="footer">Content available under a <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License.">Creative Commons Attribution-ShareAlike 4.0 International License</a> <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License."><img alt="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License." style="border-width:0" src="images/creative_commons_attribution_share_alike_4.0_international_licence_88x31.png" /></a></div>
</body>
</html>

View File

@ -0,0 +1,130 @@
<%@page import="org.nanoboot.powerframework.time.moment.LocalDate"%>
<%@page import="org.nanoboot.nanodata.web.misc.utils.Utils"%>
<%@page import="org.nanoboot.nanodata.persistence.api.UrlRepo"%>
<%@page import="org.nanoboot.nanodata.entity.Url"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="org.apache.commons.fileupload.FileUploadException"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.commons.io.output.*"%>
<!DOCTYPE>
<!--
Nanodata.
Copyright (C) 2023-2023 the original author or authors.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<%@ page session="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Update url - Nanodata</title>
<link rel="stylesheet" type="text/css" href="styles/nanodata.css">
<link rel="icon" type="image/x-icon" href="favicon.ico" sizes="32x32">
</head>
<body>
<a href="index.jsp" id="main_title">Nanodata</a></span>
<%
String id = request.getParameter("id");
if (id == null || id.isEmpty()) {
%><span style="font-weight:bold;color:red;" class="margin_left_and_big_font">Error: Parameter "id" is required</span>
<%
throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<span class="nav"><a href="index.jsp">Home</a>
>> <a href="urls.jsp">Urls</a>
>> <a href="read_url.jsp?id=<%=id%>">Read</a>
<a href="update_url.jsp?id=<%=id%>">Update</a>
<a href="delete_url.jsp?id=<%=id%>" class="nav_a_current">Delete</a>
</span>
<%
if (org.nanoboot.nanodata.web.misc.utils.Utils.cannotUpdate(request)) {
out.println("Access forbidden");
throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
UrlRepo urlRepo = context.getBean("urlRepoImplSqlite", UrlRepo.class);
Url url = urlRepo.read(id);
if (url == null) {
%><span style="font-weight:bold;color:red;" class="margin_left_and_big_font">Error: url with id <%=id%> was not found.</span>
<%
throw new jakarta.servlet.jsp.SkipPageException();
}
String param_user_agree_to_delete_this_url = request.getParameter("user_agree_to_delete_this_url");
boolean formToBeProcessed = param_user_agree_to_delete_this_url != null && !param_user_agree_to_delete_this_url.isEmpty();
%>
<% if (!formToBeProcessed) {%>
<form action="delete_url.jsp" method="get">
<input type="hidden" name="id" value="<%=id%>" readonly></td>
<input type="hidden" name="user_agree_to_delete_this_url" value="yes">
<a href="urls.jsp" style="font-size:130%;background:#dddddd;border:2px solid #bbbbbb;padding:2px;text-decoration:none;">Cancel</a></td>
<input type="submit" value="Delete forever">
</form>
<% } else { %>
<%
urlRepo.delete(id);
%>
<script>
function redirectToList() {
window.location.href = 'urls.jsp?id=<%=id%>'
}
redirectToList();
</script>
<% }%>
<div id="footer">Content available under a <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License.">Creative Commons Attribution-ShareAlike 4.0 International License</a> <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License."><img alt="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License." style="border-width:0" src="images/creative_commons_attribution_share_alike_4.0_international_licence_88x31.png" /></a></div>
</body>
</html>

View File

@ -35,7 +35,8 @@
<span class="nav"><a href="index.jsp" class="nav_a_current">Home</a>
>> <a href="items.jsp">Items</a>
<a href="statements.jsp">Statements</a></span>
<a href="statements.jsp">Statements</a>
<a href="urls.jsp">Urls</a></span>
<% boolean canUpdate = org.nanoboot.nanodata.web.misc.utils.Utils.canUpdate(request); %>

View File

@ -76,7 +76,6 @@
String label = request.getParameter("label");
String disambiguation = request.getParameter("disambiguation");
String description = request.getParameter("description");
String url = request.getParameter("url");
String aliases = request.getParameter("aliases");
String entryPointItem = request.getParameter("entryPointItem");
@ -102,8 +101,7 @@
<label for="label">Label</label><input type="text" name="label" value="<%=label != null ? label : ""%>" style="margin-right:10px;max-width:100px;">
<label for="disambiguation">Disambiguation</label><input type="text" name="disambiguation" <%=disambiguation != null ? disambiguation : ""%> style="max-width:100px;">
<label for="description">Description</label><input type="text" name="description" <%=description != null ? description : ""%> style="max-width:100px;">
<!--<label for="url">Url</label><input type="text" name="description" <%=url != null ? url : ""%> style="max-width:100px;">-->
<label for="aliases">Aliases</label><input type="text" name="aliases" <%=aliases != null ? aliases : ""%> style="max-width:100px;">
<label for="aliases">Aliases</label><input type="text" name="aliases" <%=aliases != null ? aliases : ""%> style="max-width:100px;">
<label for="entryPointItem">Entry Point Item</label><input type="checkbox" name="entryPointItem" <%=entryPointItem != null && entryPointItem.equals("1") ? "checked " : ""%>value="1">
<input type="submit" value="Filter" style="margin-left:20px;height:40px;">
@ -141,7 +139,6 @@
<th>Label</th>
<th>Disambiguation</th>
<th>Description</th>
<th>Url</th>
<th>Aliases</th>
<th>Entry Point Item</th>
</tr>
@ -188,7 +185,6 @@
<td><%=i.getDisambiguation() == null ? EMPTY : i.getDisambiguation()%></td>
<td><%=i.getDescription() == null ? EMPTY : i.getDescription()%></td>
<td><%=i.getUrl() == null ? EMPTY : Utils.formatToHtml(i.getUrl())%></td>
<td><%=i.getAliases() == null ? EMPTY : i.getAliases()%></td>
<td><%=org.nanoboot.nanodata.web.misc.utils.Utils.formatToHtml(i.getEntryPointItem())%></td>

View File

@ -1,8 +1,10 @@
<%@page import="org.nanoboot.nanodata.web.misc.utils.Utils"%>
<%@page import="org.nanoboot.nanodata.persistence.api.ItemRepo"%>
<%@page import="org.nanoboot.nanodata.persistence.api.StatementRepo"%>
<%@page import="org.nanoboot.nanodata.persistence.api.UrlRepo"%>
<%@page import="org.nanoboot.nanodata.entity.Item"%>
<%@page import="org.nanoboot.nanodata.entity.Statement"%>
<%@page import="org.nanoboot.nanodata.entity.Url"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="java.util.Scanner"%>
@ -81,6 +83,7 @@
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
StatementRepo statementRepo = context.getBean("statementRepoImplSqlite", StatementRepo.class);
UrlRepo urlRepo = context.getBean("urlRepoImplSqlite", UrlRepo.class);
ItemRepo itemRepo = context.getBean("itemRepoImplSqlite", ItemRepo.class);
Item item = itemRepo.read(id);
@ -140,18 +143,21 @@
}
</script>
<style>
.section_header {
color:green;font-weight:700;border:2px solid blue;background:yellow;font-size:140%;margin:20px;padding:5px;display:block;max-width:350px;
}
</style>
<span style="color:green;font-weight:700;border:2px solid blue;background:yellow;font-size:200%;margin:20px;padding:5px;display:block;max-width:400px;">Data</span>
<span class="section_header">Data</span>
<table ondblclick = "redirectToUpdate()">
<tr>
<th>ID</th><td><%=item.getId()%> <button onclick="copyId()">Copy</button></td></tr>
<tr><th>Label</th><td><%=item.getLabel()%></a></td></tr>
<tr><th>Disambiguation</th><td><%=Utils.formatToHtml(item.getDisambiguation())%></td></tr>
<tr><th>Description</th><td><%=Utils.formatToHtml(item.getDescription())%></td></tr>
<tr><th>Url</th><td><%=Utils.formatToHtml(item.getUrl())%></td></tr>
<tr><th>Attributes</th><td><pre><%=Utils.formatToHtml(item.getAttributes())%></pre></td></tr>
<tr><th>Aliases</th><td><%=Utils.formatToHtml(item.getAliases())%></td></tr>
<tr><th>Entry Point Item</th><td><%=Utils.formatToHtml(item.getEntryPointItem())%></td></tr>
@ -160,7 +166,7 @@
</table>
<span style="color:green;font-weight:700;border:2px solid blue;background:yellow;font-size:200%;margin:20px;padding:5px;display:block;max-width:400px;">Statements</span>
<span class="section_header">Statements</span>
<% if(canUpdate) { %>
<a href="create_statement.jsp?source=<%=item.getId()%>" style="margin-left:20px;font-size:110%;background:#dddddd;border:2px solid #bbbbbb;padding:1px;text-decoration:none;margin-bottom:20px !important;">Add</a>
@ -253,7 +259,12 @@
<% } %>
<span style="color:green;font-weight:700;border:2px solid blue;background:yellow;font-size:200%;margin:20px;padding:5px;display:block;max-width:400px;">Reverse statements</span>
<span class="section_header">Reverse statements</span>
<!--<a href="create_statement.jsp?source=<%=item.getId()%>" style="margin-left:20px;font-size:110%;background:#dddddd;border:2px solid #bbbbbb;padding:1px;text-decoration:none;margin-bottom:20px !important;">Add</a>-->
<%
@ -290,24 +301,6 @@
<tbody>
<style>
tr td a img {
border:2px solid grey;
background:#dddddd;
padding:4px;
width:30%;
height:30%;
}
tr td a img:hover {
border:3px solid #888888;
padding:2px;
}
tr td {
padding-right:2px;
}
</style>
<%
for (Statement i: reverseStatements) {
@ -343,7 +336,92 @@
<span style="color:green;font-weight:700;border:2px solid blue;background:yellow;font-size:200%;margin:20px;padding:5px;display:block;max-width:400px;">Content</span>
<span class="section_header">Urls</span>
<% if(canUpdate) { %>
<a href="create_url.jsp?item_id=<%=item.getId()%>" style="margin-left:20px;font-size:110%;background:#dddddd;border:2px solid #bbbbbb;padding:1px;text-decoration:none;margin-bottom:20px !important;">Add</a>
<br><br>
<%}%>
<%
List<Url> urls = urlRepo.list(
1,
100,
null,
null,
item.getId()
);
if (urls.isEmpty()) {
%><span style="font-weight:bold;color:orange;" class="margin_left_and_big_font">Nothing found.</span>
<%
} else {
%>
<table>
<thead>
<tr>
<!--<th title="ID">ID</th>-->
<th style="width:170px;"></th>
<th>Url</th>
<th>Name</th>
<th>Item</th>
<th>Official</th>
</tr>
</thead>
<tbody>
<%
for (Url u: urls) {
%>
<tr>
<!--<td><%=u.getId()%></td>-->
<td>
<a href="read_url.jsp?id=<%=u.getId()%>">Read</a>
<!--<% if(canUpdate) { %><a href="update_item.jsp?id=<%=u.getId()%>"><img src="images/update.png" title="Update" width="48" height="48" /></a><%}%>-->
<% if(canUpdate) { %>
<a href="update_url.jsp?id=<%=u.getId()%>">Update</a>
<a href="delete_url.jsp?id=<%=u.getId()%>" target="_blank">Delete</a>
<%}%>
</td>
<td><a href="<%=u.getUrl()%>"><%=u.getUrl()%></a></td>
<td><%=u.getName()%></td>
<td><a href="read_item.jsp?id=<%=u.getItemId()%>"><%=itemRepo.getLabel(u.getItemId())%></a></td>
<td><%=Utils.formatToHtml(u.getOfficial())%></td>
</tr>
<%
}
%>
</tbody>
</table>
<% } %>
<span class="section_header">Content</span>
<%
String filePath = System.getProperty("nanodata.confpath") + "/" + "content/" + id.charAt(0) + id.charAt(1) + "/" + id.charAt(2) + id.charAt(3) + "/"+ id ;
File dir = new File(filePath);
@ -369,7 +447,7 @@ System.err.println("filePath=" + filePath);
}
%>
<span style="color:green;font-weight:700;border:2px solid blue;background:yellow;font-size:200%;margin:20px;padding:5px;display:block;max-width:400px;">Files</span>
<span class="section_header">Files</span>
<ul style="font-size:120%;line-height:160%;">
<%

View File

@ -0,0 +1,133 @@
<%@page import="org.nanoboot.nanodata.web.misc.utils.Utils"%>
<%@page import="org.nanoboot.nanodata.persistence.api.UrlRepo"%>
<%@page import="org.nanoboot.nanodata.persistence.api.ItemRepo"%>
<%@page import="org.nanoboot.nanodata.entity.Url"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="java.util.Scanner"%>
<%@page import="java.io.File"%>
<%@page import="java.util.Comparator"%>
<%@page import="java.util.Collections"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<!DOCTYPE>
<%@ page session="false" %>
<!--
Nanodata.
Copyright (C) 2023-2023 the original author or authors.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Read url - Nanodata</title>
<link rel="stylesheet" type="text/css" href="styles/nanodata.css">
<link rel="icon" type="image/x-icon" href="favicon.ico" sizes="32x32">
</head>
<body>
<a href="index.jsp" id="main_title">Nanodata</a></span>
<%
String id = request.getParameter("id");
if (id == null || id.isEmpty()) {
%><span style="font-weight:bold;color:red;" class="margin_left_and_big_font">Error: Parameter "id" is required</span>
<%
throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<span class="nav"><a href="index.jsp">Home</a>
>> <a href="urls.jsp">Urls</a>
>>
<a href="read_url.jsp?id=<%=id%>" class="nav_a_current">Read</a>
<% boolean canUpdate = org.nanoboot.nanodata.web.misc.utils.Utils.canUpdate(request); %>
<% if(canUpdate) { %>
<a href="update_url.jsp?id=<%=id%>">Update</a>
<a href="delete_url.jsp?id=<%=id%>">Delete</a>
<% } %>
</span>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
UrlRepo urlRepo = context.getBean("urlRepoImplSqlite", UrlRepo.class);
ItemRepo itemRepo = context.getBean("itemRepoImplSqlite", ItemRepo.class);
Url url = urlRepo.read(id);
if (url == null) {
%><span style="font-weight:bold;color:red;" class="margin_left_and_big_font">Error: Url with id <%=id%> was not found.</span>
<%
throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<style>
th{
text-align:left;
background:#cccccc;
}
</style>
<!--
<p class="margin_left_and_big_font">
<a href="read_statement.jsp?id=<%=url.getId()%>&previous_next=previous" class="button">Previous</a>
<a href="read_statement.jsp?id=<%=url.getId()%>&previous_next=next" class="button">Next</a>
<br><br>
</p>
-->
<script>
function redirectToUpdate() {
<% if(canUpdate) { %>
window.location.href = 'update_url.jsp?id=<%=id%>'
<% } %>
}
</script>
<table ondblclick = "redirectToUpdate()">
<tr>
<th>ID</th><td><%=url.getId()%></td></tr>
<tr><th>Url</th><td><a href="<%=url.getUrl()%>"><%=url.getUrl()%></a></td></tr>
<tr><th>Name</th><td><%=Utils.formatToHtml(url.getName())%></td></tr>
<tr><th>Item</th><td><a href="read_item.jsp?id=<%=url.getItemId()%>"><%=itemRepo.getLabel(url.getItemId())%></a></td></tr>
<tr><th>Official</th><td><%=Utils.formatToHtml(url.getOfficial())%></td></tr>
<tr><th>Created at</th><td><%=url.getCreatedAt()%></a></td></tr>
</table>
<div id="footer">Content available under a <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License.">Creative Commons Attribution-ShareAlike 4.0 International License</a> <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License."><img alt="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License." style="border-width:0" src="images/creative_commons_attribution_share_alike_4.0_international_licence_88x31.png" /></a></div>
</body>
</html>

View File

@ -107,10 +107,6 @@
<td><label for="description">Description:</label></td>
<td><input type="text" name="description" value="<%=item.getDescription() == null ? "" : item.getDescription()%>"></td>
</tr>
<tr>
<td><label for="url">Url</label></td>
<td><input type="text" name="url" value="<%=item.getUrl() == null ? "" : item.getUrl()%>"></td>
</tr>
<tr>
<td><label for="attributes">Attributes:</label></td>
<td><textarea style="width:100%;height:100px;" name="attributes"><%=item.getAttributes() == null ? "" : item.getAttributes()%></textarea></td>
@ -151,7 +147,6 @@
String param_disambiguation = request.getParameter("disambiguation");
String param_description = request.getParameter("description");
String param_url = request.getParameter("url");
String param_attributes = request.getParameter("attributes");
String param_aliases = request.getParameter("aliases");
@ -163,9 +158,6 @@
if (param_description != null && param_description.isEmpty()) {
param_description = null;
}
if (param_url != null && param_url.isEmpty()) {
param_url = null;
}
if (param_attributes != null && param_attributes.isEmpty()) {
param_attributes = null;
}
@ -183,7 +175,6 @@
param_label,
param_disambiguation,
param_description,
param_url,
param_attributes,
param_aliases,
param_entryPointItem == null ? null : Boolean.valueOf(param_entryPointItem.equals("1")),

View File

@ -0,0 +1,173 @@
<%@page import="org.nanoboot.powerframework.time.moment.LocalDate"%>
<%@page import="org.nanoboot.nanodata.web.misc.utils.Utils"%>
<%@page import="org.nanoboot.nanodata.persistence.api.UrlRepo"%>
<%@page import="org.nanoboot.nanodata.entity.Url"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="org.apache.commons.fileupload.FileUploadException"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.commons.io.output.*"%>
<!DOCTYPE>
<!--
Nanodata.
Copyright (C) 2023-2023 the original author or authors.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<%@ page session="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Update url - Nanodata</title>
<link rel="stylesheet" type="text/css" href="styles/nanodata.css">
<link rel="icon" type="image/x-icon" href="favicon.ico" sizes="32x32">
</head>
<body>
<a href="index.jsp" id="main_title">Nanodata</a></span>
<%
String id = request.getParameter("id");
if (id == null || id.isEmpty()) {
%><span style="font-weight:bold;color:red;" class="margin_left_and_big_font">Error: Parameter "id" is required</span>
<%
throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<span class="nav"><a href="index.jsp">Home</a>
>> <a href="urls.jsp">Urls</a>
>> <a href="read_url.jsp?id=<%=id%>">Read</a>
<a href="update_url.jsp?id=<%=id%>" class="nav_a_current">Update</a>
<a href="delete_url.jsp?id=<%=id%>">Delete</a>
</span>
<%
if (org.nanoboot.nanodata.web.misc.utils.Utils.cannotUpdate(request)) {
out.println("Access forbidden");
throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
UrlRepo urlRepo = context.getBean("urlRepoImplSqlite", UrlRepo.class);
Url url = urlRepo.read(id);
if (url == null) {
%><span style="font-weight:bold;color:red;" class="margin_left_and_big_font">Error: url with id <%=id%> was not found.</span>
<%
throw new jakarta.servlet.jsp.SkipPageException();
}
String param_url = request.getParameter("url");
boolean formToBeProcessed = param_url != null && !param_url.isEmpty();
%>
<% if (!formToBeProcessed) {%>
<form action="update_url.jsp" method="get">
<table>
<tr>
<td><label for="id">ID <b style="color:red;font-size:130%;">*</b>:</label></td>
<td><input type="text" name="id" value="<%=id%>" readonly style="background:#dddddd;"></td>
</tr>
<tr>
<td><label for="url">Url <b style="color:red;font-size:130%;">*</b>:</label></td>
<td><input type="text" name="url" value="<%=url.getUrl()%>"></td>
</tr>
<tr>
<td><label for="name">Name</label></td>
<td><input type="text" name="name" value="<%=url.getName() == null ? "" : url.getName()%>"></td>
</tr>
<tr>
<td><label for="item_id">Item id</label></td>
<td><input type="text" name="item_id" value="<%=url.getItemId()%>"></td>
</tr>
<tr>
<td><label for="official">Official</label></td>
<td style="text-align:left;">
<input type="checkbox" name="official" value="1" <%=url.getOfficial().booleanValue() ? "checked" : ""%> >
</td>
</tr>
<tr>
<td><a href="urls.jsp" style="font-size:130%;background:#dddddd;border:2px solid #bbbbbb;padding:2px;text-decoration:none;">Cancel</a></td>
<td style="text-align:right;"><input type="submit" value="Update"></td>
</tr>
</table>
<b style="color:red;font-size:200%;margin-left:20px;">*</b> ...mandatory
</form>
<% } else { %>
<%
String param_name = request.getParameter("name");
String param_official = request.getParameter("official");
if(param_official == null) {
param_official = "0";
}
String param_item_id = request.getParameter("item_id");
//
Url updatedUrl = new Url(
id,
param_url,
param_name,
param_item_id,
Boolean.valueOf(param_official.equals("1")),
null
);
urlRepo.update(updatedUrl);
%>
<script>
function redirectToRead() {
window.location.href = 'read_url.jsp?id=<%=id%>'
}
redirectToRead();
</script>
<% }%>
<div id="footer">Content available under a <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License.">Creative Commons Attribution-ShareAlike 4.0 International License</a> <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License."><img alt="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License." style="border-width:0" src="images/creative_commons_attribution_share_alike_4.0_international_licence_88x31.png" /></a></div>
</body>
</html>

View File

@ -0,0 +1,205 @@
<%@page import="java.util.List"%>
<%@page import="org.nanoboot.nanodata.persistence.api.UrlRepo"%>
<%@page import="org.nanoboot.nanodata.persistence.api.ItemRepo"%>
<%@page import="org.nanoboot.nanodata.entity.Url"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.nanoboot.nanodata.web.misc.utils.Utils"%>
<!DOCTYPE>
<%@ page session="false" %>
<!--
Nanodata.
Copyright (C) 2023-2023 the original author or authors.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>List urls - Nanodata</title>
<link rel="stylesheet" type="text/css" href="styles/nanodata.css">
<link rel="icon" type="image/x-icon" href="favicon.ico" sizes="32x32">
</head>
<body>
<a href="index.jsp" id="main_title">Nanodata</a></span>
<span class="nav"><a href="index.jsp">Home</a>
>> <a href="urls.jsp" class="nav_a_current">Urls</a>
<% boolean canUpdate = org.nanoboot.nanodata.web.misc.utils.Utils.canUpdate(request); %>
<% if(canUpdate) { %>
>> <a href="create_url.jsp">Add Url</a>
<% } %>
</span>
<%
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
UrlRepo urlRepo = context.getBean("urlRepoImplSqlite", UrlRepo.class);
ItemRepo itemRepo = context.getBean("itemRepoImplSqlite", ItemRepo.class);
%>
<style>
input[type="submit"] {
padding-top: 15px !important;
padding-left:10px;
padding-right:10px;
border:2px solid #888 !important;
font-weight:bold;
}
input[type="checkbox"] {
margin-right:20px;
}
</style>
<%
final String EMPTY = "<span style=\"color:grey;font-size:75%;\">[empty]</span>";
String id = request.getParameter("id");
String url = request.getParameter("url");
if(url == null) {url = "";}
String name = request.getParameter("name");
if(name == null) {name = "";}
String item_id = request.getParameter("item_id");
if(item_id == null) {item_id = "";}
String official = request.getParameter("official");
String pageNumber = request.getParameter("pageNumber");
String previousNextPage = request.getParameter("PreviousNextPage");
if (previousNextPage != null && !previousNextPage.isEmpty()) {
if (previousNextPage.equals("Previous page")) {
pageNumber = String.valueOf(Integer.valueOf(pageNumber) - 1);
}
if (previousNextPage.equals("Next page")) {
pageNumber = String.valueOf(Integer.valueOf(pageNumber) + 1);
}
}
int pageNumberInt = pageNumber == null || pageNumber.isEmpty() ? 1 : Integer.valueOf(pageNumber);
%>
<form action="urls.jsp" method="get">
<label for="pageNumber">Page </label><input type="text" name="pageNumber" value="<%=pageNumberInt%>" size="4" style="margin-right:10px;">
<label for="id">ID</label><input type="text" name="id" value="<%=id != null ? id : ""%>" size="5" style="margin-right:10px;">
<label for="url">Url</label><input type="text" name="url" value="<%=url%>" style="margin-right:10px;max-width:100px;">
<label for="name">Name</label><input type="text" name="name" value="<%=name != null ? name : ""%>" style="max-width:100px;">
<label for="item_id">Item id</label><input type="text" name="item_id" value="<%=item_id%>" style="max-width:100px;">
<label for="official">Official</label><input type="checkbox" name="official" <%=official != null && official.equals("1") ? "checked " : ""%>value="1">
<input type="submit" value="Filter" style="margin-left:20px;height:40px;">
<br>
<br>
<input type="submit" name="PreviousNextPage" value="Previous page" style="margin-left:20px;height:40px;">
<input type="submit" name="PreviousNextPage" value="Next page" style="margin-left:20px;height:40px;">
</form>
<%
List<Url> urls = urlRepo.list(
pageNumberInt,
10,
null,
null,
null
);
if (urls.isEmpty()) {
%><span style="font-weight:bold;color:orange;" class="margin_left_and_big_font">Warning: Nothing found.</span>
<% throw new jakarta.servlet.jsp.SkipPageException();
}
%>
<table>
<thead>
<tr>
<!--<th title="ID">ID</th>-->
<th style="width:170px;"></th>
<th>Url</th>
<th>Name</th>
<th>Item</th>
<th>Official</th>
</tr>
</thead>
<tbody>
<style>
tr td a img {
border:2px solid grey;
background:#dddddd;
padding:4px;
width:30%;
height:30%;
}
tr td a img:hover {
border:3px solid #888888;
padding:3px;
}
tr td {
padding-right:0;
}
</style>
<%
for (Url u: urls) {
%>
<tr>
<!--<td><%=u.getId()%></td>-->
<td>
<a href="read_url.jsp?id=<%=u.getId()%>">Read</a>
<!--<a href="read_item.jsp?id=<%=u.getId()%>"><img src="images/read.png" title="View" width="48" height="48" /></a>-->
<!--<% if(canUpdate) { %><a href="update_item.jsp?id=<%=u.getId()%>"><img src="images/update.png" title="Update" width="48" height="48" /></a><%}%>-->
<% if(canUpdate) { %>
<a href="update_url.jsp?id=<%=u.getId()%>">Update</a>
<a href="delete_url.jsp?id=<%=u.getId()%>" target="_blank">Delete</a>
<%}%>
</td>
<td><a href="<%=u.getUrl()%>"><%=u.getUrl()%></a></td>
<td><%=u.getName()%></td>
<td><a href="read_item.jsp?id=<%=u.getItemId()%>"><%=itemRepo.getLabel(u.getItemId())%></a></td>
<td><%=Utils.formatToHtml(u.getOfficial())%></td>
</tr>
<%
}
%>
</tbody>
</table>
<div id="footer">Content available under a <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License.">Creative Commons Attribution-ShareAlike 4.0 International License</a> <a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" title="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License."><img alt="Content available under a Creative Commons Attribution-ShareAlike 4.0 International License." style="border-width:0" src="images/creative_commons_attribution_share_alike_4.0_international_licence_88x31.png" /></a></div>
</body>
</html>