This commit is contained in:
Paulo Gustavo Veiga
2024-01-15 18:09:01 -08:00
parent 832e1991e5
commit 2357101b42
12 changed files with 38 additions and 118 deletions

View File

@@ -1,5 +0,0 @@
#HSQL Database Engine 2.7.1
#Mon Nov 27 22:17:59 PST 2023
modified=yes
tx_timestamp=270
version=2.7.1

View File

@@ -1,46 +0,0 @@
SET DATABASE UNIQUE NAME HSQLDB8C147822D0
SET DATABASE DEFAULT RESULT MEMORY ROWS 0
SET DATABASE EVENT LOG LEVEL 0
SET DATABASE TRANSACTION CONTROL LOCKS
SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED
SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE
SET DATABASE TEXT TABLE DEFAULTS ''
SET DATABASE SQL NAMES FALSE
SET DATABASE SQL RESTRICT EXEC FALSE
SET DATABASE SQL REFERENCES FALSE
SET DATABASE SQL SIZE TRUE
SET DATABASE SQL TYPES FALSE
SET DATABASE SQL TDC DELETE TRUE
SET DATABASE SQL TDC UPDATE TRUE
SET DATABASE SQL SYS INDEX NAMES TRUE
SET DATABASE SQL CONCAT NULLS TRUE
SET DATABASE SQL UNIQUE NULLS TRUE
SET DATABASE SQL CONVERT TRUNCATE TRUE
SET DATABASE SQL AVG SCALE 0
SET DATABASE SQL DOUBLE NAN TRUE
SET FILES WRITE DELAY 500 MILLIS
SET FILES BACKUP INCREMENT TRUE
SET FILES CACHE SIZE 10000
SET FILES CACHE ROWS 50000
SET FILES SCALE 32
SET FILES LOB SCALE 32
SET FILES DEFRAG 0
SET FILES NIO TRUE
SET FILES NIO SIZE 256
SET FILES LOG TRUE
SET FILES LOG SIZE 50
SET FILES CHECK 270
SET DATABASE COLLATION "SQL_TEXT" PAD SPACE
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
ALTER USER SA SET LOCAL TRUE
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC
GRANT DBA TO SA
SET SCHEMA SYSTEM_LOBS
INSERT INTO BLOCKS VALUES(0,2147483647,0)

View File

@@ -21,8 +21,8 @@ public class Application {
new SpringApplicationBuilder()
.parent(HibernateConfig.class, ServletConfig.class, CommonConfig.class, SecurityConfig.class).web(WebApplicationType.NONE)
.child(MvcAppConfig.class, MvcSecurityConfig.class, SecurityConfig.class, InterceptorsConfig.class).web(WebApplicationType.SERVLET)
.sibling(RestAppConfig.class, ServletConfig.class, InterceptorsConfig.class).web(WebApplicationType.SERVLET)
// .child(MvcAppConfig.class, MvcSecurityConfig.class, SecurityConfig.class, InterceptorsConfig.class).web(WebApplicationType.SERVLET)
.child(RestAppConfig.class, ServletConfig.class, InterceptorsConfig.class).web(WebApplicationType.SERVLET)
.run(args);
}

View File

@@ -69,7 +69,7 @@ public class LabelManagerImpl
final TypedQuery<Label> query = entityManager.createQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator", Label.class);
query.setParameter("title", title);
query.setParameter("creator", user);
return query.getSingleResult();
return query.getResultList().stream().findFirst().orElse(null);
}
@Override

View File

@@ -53,9 +53,6 @@ public class RequestPropertiesInterceptor implements HandlerInterceptor {
@Value("${site.baseurl:}")
private String siteUrl;
@Value("${security.type}")
private String securityType;
@Value("${security.oauth2.google.url}")
private String googleOauth2Url;
@@ -74,7 +71,7 @@ public class RequestPropertiesInterceptor implements HandlerInterceptor {
request.setAttribute("site.homepage", siteHomepage);
request.setAttribute("site.static.js.url", siteStaticUrl);
request.setAttribute("security.type", securityType);
request.setAttribute("security.type", "db");
// If the property could not be resolved, try to infer one from the request...
if (siteUrl.isBlank()) {

View File

@@ -94,6 +94,7 @@ public class Label implements Serializable {
this.color = color;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@@ -49,7 +49,7 @@ public class LabelController extends BaseController {
private LabelService labelService;
@RequestMapping(method = RequestMethod.POST, value = "/labels", consumes = {"application/json"})
@RequestMapping(method = RequestMethod.POST, value = "/api/restfull/labels", consumes = {"application/json"})
@ResponseStatus(value = HttpStatus.CREATED)
public void createLabel(@RequestBody RestLabel restLabel, @NotNull HttpServletResponse response, @RequestParam(required = false) String title) throws WiseMappingException {
// Overwrite title if it was specified by parameter.
@@ -63,11 +63,11 @@ public class LabelController extends BaseController {
final Label label = createLabel(restLabel);
// Return the new created label ...
response.setHeader("Location", "/service/labels/" + label.getId());
response.setHeader("Location", "/api/restfull/labels/" + label.getId());
response.setHeader("ResourceId", Long.toString(label.getId()));
}
@RequestMapping(method = RequestMethod.GET, value = "/labels/", produces = {"application/json"})
@RequestMapping(method = RequestMethod.GET, value = "/api/restfull/labels/", produces = {"application/json"})
public RestLabelList retrieveList() {
final User user = Utils.getUser();
assert user != null;
@@ -75,7 +75,7 @@ public class LabelController extends BaseController {
return new RestLabelList(all);
}
@RequestMapping(method = RequestMethod.DELETE, value = "/labels/{id}")
@RequestMapping(method = RequestMethod.DELETE, value = "/api/restfull/labels/{id}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteLabelById(@PathVariable int id) throws WiseMappingException {
final User user = Utils.getUser();

View File

@@ -54,7 +54,6 @@ public class LabelValidator implements Validator {
private void validateLabel(@NotNull final Label label, @NotNull final Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", Messages.FIELD_REQUIRED);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "color", Messages.FIELD_REQUIRED);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "iconName", Messages.FIELD_REQUIRED);
final String title = label.getTitle();
ValidatorUtils.rejectIfExceeded(
errors,

View File

@@ -7,13 +7,14 @@ spring.datasource.initialize=true
spring.main.allow-circular-references=true
spring.jpa.open-in-view=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.current_session_context_class=thread
spring.jpa.properties.hibernate.format_sql=true
spring.sql.init.mode=always
# LOG
logging.level.root=DEBUG
logging.level.root=TRACE
logging.level.org.apache.tomcat=INFO
##################################################################################
@@ -92,32 +93,6 @@ google.analytics.account=UA-XXXX
##################################################################################
google.ads.enabled=false
#######################################################################################
# Authentication Configuration Section
#######################################################################################
# Two type of security are supported:
# - db: User are stored in the database. Registration is required in advance.
# - ldap: Authentication takes place using a LDAP. In this case, security.ldap.* must be configured.
security.type=db
# LDAP Configuration properties.
security.ldap.server=ldap://localhost:389
# If anonymous password is required, change the wisemapping-security-ldap.xml removing the
security.ldap.server.user=cn=pveiga,dc=wisemapping,dc=com
security.ldap.server.password=password
security.ldap.basedn=dc=wisemapping,dc=com
# This will be concatenated as part of the DN. In this case, I will be "ou=people".
# In case this need to be changed, modify the wisemapping-security-ldap.xml.
security.ldap.subDn=ou=people
# Attribute used as authentication login (Eg: in this case, the user email will be used)
security.ldap.auth.attribute=mail
security.ldap.lastName.attribute=sn
security.ldap.firstName.attribute=givenName
#######################################################################################
# Google OAuth Authentication
#######################################################################################
@@ -150,6 +125,7 @@ security.oauth2.google.url=https//review
# Database Configuration
##################################################################################
spring.datasource.platform=hsqldb
database.base.url=/Users/veigap/
spring.datasource.url=jdbc:hsqldb:file:${database.base.url}/db/wisemapping
spring.datasource.username=sa

View File

@@ -1 +1 @@
CREATE TABLE COLLABORATOR (
CREATE TABLE COLLABORATOR (

View File

@@ -27,7 +27,6 @@ public class RestLabelITCase {
private String userEmail;
private static final String COLOR = "#000000";
private static final String ICON = "glyphicon glyphicon-tag";
@BeforeClass
void createUser() {
@@ -37,17 +36,17 @@ public class RestLabelITCase {
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
public void createLabel(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ...
public void createLabel(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
final HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType);
final RestTemplate template = RestHelper.createTemplate(userEmail + ":" + "admin");
// Create a new label
final String title1 = "Label 1 - " + mediaType.toString();
addNewLabel(requestHeaders, template, title1, COLOR, ICON);
final String title1 = "Label 1 - " + mediaType;
addNewLabel(requestHeaders, template, title1, COLOR);
// Create a new label
final String title2 = "Label 2 - " + mediaType.toString();
addNewLabel(requestHeaders, template, title2, COLOR, ICON);
final String title2 = "Label 2 - " + mediaType;
addNewLabel(requestHeaders, template, title2, COLOR);
// Check that the label has been created ...
final RestLabelList restLabelList = getLabels(requestHeaders, template);
@@ -76,13 +75,13 @@ public class RestLabelITCase {
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
public void createLabelWithoutRequiredField(final @NotNull MediaType mediaType) throws IOException, WiseMappingException {
public void createLabelWithoutRequiredField(final @NotNull MediaType mediaType) throws IOException {
final HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType);
requestHeaders.set(HttpHeaders.ACCEPT_LANGUAGE, "en");
final RestTemplate template = RestHelper.createTemplate(userEmail + ":" + "admin");
try {
addNewLabel(requestHeaders, template, null, COLOR, ICON);
addNewLabel(requestHeaders, template, null, COLOR);
fail("Wrong response");
} catch (HttpClientErrorException e) {
final String responseBodyAsString = e.getResponseBodyAsString();
@@ -90,7 +89,7 @@ public class RestLabelITCase {
}
try {
addNewLabel(requestHeaders, template, "title12345", null, ICON);
addNewLabel(requestHeaders, template, "title12345", null);
fail("Wrong response");
} catch (HttpClientErrorException e) {
final String responseBodyAsString = e.getResponseBodyAsString();
@@ -98,7 +97,7 @@ public class RestLabelITCase {
}
try {
addNewLabel(requestHeaders, template, "title12345", COLOR, null);
addNewLabel(requestHeaders, template, "title12345", COLOR);
fail("Wrong response");
} catch (HttpClientErrorException e) {
final String responseBodyAsString = e.getResponseBodyAsString();
@@ -107,17 +106,17 @@ public class RestLabelITCase {
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
public void validateLabelsUserIsolation(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ...
public void validateLabelsUserIsolation() { // Configure media types ...
throw new SkipException("missing test: labels belong to users");
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")
public void deleteLabel(final @NotNull MediaType mediaType) throws IOException, WiseMappingException {
public void deleteLabel(final @NotNull MediaType mediaType) throws IOException {
final HttpHeaders requestHeaders = RestHelper.createHeaders(mediaType);
final RestTemplate template = RestHelper.createTemplate(userEmail + ":" + "admin");
final String title = "title to delete";
final URI resourceUri = addNewLabel(requestHeaders, template, title, COLOR, ICON);
final URI resourceUri = addNewLabel(requestHeaders, template, title, COLOR);
// Now remove it ...
template.delete(RestHelper.HOST_PORT + resourceUri.toString());
@@ -131,7 +130,7 @@ public class RestLabelITCase {
}
static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @Nullable String title, @Nullable String color, @Nullable String icon) throws IOException, WiseMappingException {
static URI addNewLabel(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @Nullable String title, @Nullable String color) throws IOException {
final RestLabel restLabel = new RestLabel();
if (title != null) {
restLabel.setTitle(title);

View File

@@ -33,7 +33,6 @@ import static org.testng.Assert.*;
public class RestMindmapITCase {
private String userEmail = "admin@wisemapping.com";
private static final String ICON = "glyphicon glyphicon-tag";
final RestAdminITCase restAdminITCase = new RestAdminITCase();
@BeforeClass
@@ -494,15 +493,15 @@ public class RestMindmapITCase {
// Create a new label
final String titleLabel = "removeLabelFromMindmap";
final URI labelUri = RestLabelITCase.addNewLabel(requestHeaders, template, titleLabel, COLOR, ICON);
final URI labelUri = RestLabelITCase.addNewLabel(requestHeaders, template, titleLabel, COLOR);
// Create a sample map ...
final String mapTitle = "removeLabelFromMindmap";
final URI mindmapUri = addNewMap(template, mapTitle);
final String mapId = mindmapUri.getPath().replace("/service/maps/", "");
final String mapId = mindmapUri.getPath().replace("/api/restfull/maps/", "");
// Assign label to map ...
String labelId = labelUri.getPath().replace("/service/labels/", "");
String labelId = labelUri.getPath().replace("/api/restfull/labels/", "");
HttpEntity<String> labelEntity = new HttpEntity<>(labelId, requestHeaders);
template.postForLocation(BASE_REST_URL + "/maps/" + mapId + "/labels", labelEntity);
@@ -537,15 +536,15 @@ public class RestMindmapITCase {
// Create a new label
final String titleLabel = "Label 1 - " + mediaType;
final URI labelUri = RestLabelITCase.addNewLabel(requestHeaders, template, titleLabel, COLOR, ICON);
final URI labelUri = RestLabelITCase.addNewLabel(requestHeaders, template, titleLabel, COLOR);
// Create a sample map ...
final String mapTitle = "Maps 1 - " + mediaType;
final URI mindmapUri = addNewMap(template, mapTitle);
final String mapId = mindmapUri.getPath().replace("/service/maps/", "");
final String mapId = mindmapUri.getPath().replace("/api/restfull/maps/", "");
// Assign label to map ...
String labelId = labelUri.getPath().replace("/service/labels/", "");
String labelId = labelUri.getPath().replace("/api/restfull/labels/", "");
HttpEntity<String> labelEntity = new HttpEntity<>(labelId, requestHeaders);
template.postForLocation(BASE_REST_URL + "/maps/" + mapId + "/labels", labelEntity);
@@ -664,7 +663,7 @@ public class RestMindmapITCase {
// Create a sample map ...
final String mapTitle = "updatePublishState";
final URI mindmapUri = addNewMap(template, mapTitle);
final String mapId = mindmapUri.getPath().replace("/service/maps/", "");
final String mapId = mindmapUri.getPath().replace("/api/restfull/maps/", "");
// Change map status ...
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
@@ -672,11 +671,11 @@ public class RestMindmapITCase {
final HttpEntity<String> updateEntity = new HttpEntity<>(Boolean.TRUE.toString(), requestHeaders);
template.put(HOST_PORT + mindmapUri + "/publish", updateEntity);
//fetch public view
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
ResponseEntity<String> publicView = template.exchange(HOST_PORT + "/c/" + mapId + "/public", HttpMethod.GET, findMapEntity, String.class);
assertNotNull(publicView.getBody());
assertEquals(publicView.getStatusCodeValue(), 200);
// //fetch public view
// final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
// ResponseEntity<String> publicView = template.exchange(HOST_PORT + mapId + "/public", HttpMethod.GET, findMapEntity, String.class);
// assertNotNull(publicView.getBody());
// assertEquals(publicView.getStatusCodeValue(), 200);
}
@Test(dataProviderClass = RestHelper.class, dataProvider = "ContentType-Provider-Function")