Skip to content

Commit

Permalink
Remove local JSON code; use Maven package instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleydyr Albuquerque committed Apr 14, 2019
1 parent fe14e20 commit 065cd9c
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 6,200 deletions.
54 changes: 27 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -49,17 +50,22 @@

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -138,19 +144,13 @@
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>

<!-- dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency -->

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand All @@ -163,7 +163,7 @@
<artifactId>marc4j</artifactId>
<version>2.5.1.beta</version>
</dependency>

<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>normalizer</artifactId>
Expand Down Expand Up @@ -208,7 +208,7 @@
<artifactId>juniversalchardet</artifactId>
<version>1.0.3</version>
</dependency>

<!-- ObjectLab Kit for business days calculations -->
<dependency>
<groupId>net.objectlab.kit</groupId>
Expand Down Expand Up @@ -241,9 +241,9 @@
</dependency>
<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>
<dependency>
<groupId>javax.measure</groupId>
Expand All @@ -270,7 +270,7 @@
<target>${jdk.version}</target>
<debug>${debug}</debug>
<optimize>!${debug}</optimize>
<verbose>${debug}</verbose>
<verbose>${debug}</verbose>
<showWarnings>${debug}</showWarnings>
<showDeprecation>${debug}</showDeprecation>
</configuration>
Expand Down Expand Up @@ -302,7 +302,7 @@
</includes>
</resource>
</webResources>
</configuration>
</configuration>
</plugin>

<plugin>
Expand All @@ -314,7 +314,7 @@
<always_update>true</always_update>
<style>${sass.OutputStyle}</style>
<debug_info>${debug}</debug_info>
</sassOptions>
</sassOptions>
<useCompass>true</useCompass>
<resources>
<resource>
Expand All @@ -327,11 +327,11 @@
</source>
<destination>${basedir}/WebContent/static/styles</destination>
</resource>
</resources>
</resources>
</configuration>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
Expand Down Expand Up @@ -359,6 +359,6 @@
</configuration>
</plugin>
</plugins>
</pluginManagement>
</pluginManagement>
</build>
</project>
56 changes: 19 additions & 37 deletions src/main/java/biblivre/administration/configurations/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
package biblivre.administration.configurations;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import biblivre.core.AbstractHandler;
Expand All @@ -32,9 +30,9 @@
import biblivre.core.configurations.Configurations;
import biblivre.core.configurations.ConfigurationsDTO;
import biblivre.core.enums.ActionResult;
import biblivre.core.exceptions.ValidationException;
import biblivre.core.schemas.Schemas;
import biblivre.core.translations.Translations;
import biblivre.core.utils.Constants;

public class Handler extends AbstractHandler {

Expand All @@ -43,50 +41,34 @@ public void save(ExtendedRequest request, ExtendedResponse response) {
int loggedUser = request.getLoggedUserId();
String language = request.getLanguage();

String configurations = request.getString("configurations", "{}");
List<ConfigurationsDTO> configs = new ArrayList<ConfigurationsDTO>();
String configurations = request.getString("configurations", Constants.JSON_EMPTY_OBJECT_STR);
final List<ConfigurationsDTO> configs = new ArrayList<>();

try {
JSONObject json = new JSONObject(configurations);
JSONObject json = new JSONObject(configurations);

Iterator<String> it = json.keys();
while (it.hasNext()) {
String key = it.next();
String value = json.getString(key);
json.keys().forEachRemaining(key -> {
String value = json.getString(key);

if (key.equals("text.main.logged_in") || key.equals("text.main.logged_out")) {
Translations.addSingleTranslation(schema, language, key, value, loggedUser);
} else {
configs.add(new ConfigurationsDTO(key, value));
}
if (key.equals("text.main.logged_in") || key.equals("text.main.logged_out")) {
Translations.addSingleTranslation(schema, language, key, value, loggedUser);
} else {
configs.add(new ConfigurationsDTO(key, value));
}
} catch (JSONException e) {
this.setMessage(ActionResult.WARNING, "error.invalid_json");
return;
}
});

if (configs.size() == 0) {
return;
}

try {
configs = Configurations.validate(schema, configs);
} catch (ValidationException e) {
this.setMessage(e);
return;
}

try {
boolean multiSchemaBefore = Schemas.isMultipleSchemasEnabled();
Configurations.save(schema, configs, loggedUser);
boolean multiSchemaAfter = Schemas.isMultipleSchemasEnabled();
boolean multiSchemaBefore = Schemas.isMultipleSchemasEnabled();

this.setMessage(ActionResult.SUCCESS, "administration.configurations.save.success");
this.json.put("reload", multiSchemaBefore != multiSchemaAfter);
} catch (Exception e) {
this.setMessage(ActionResult.WARNING, "administration.configurations.error.save");
return;
}
Configurations.save(schema, Configurations.validate(schema, configs), loggedUser);

boolean multiSchemaAfter = Schemas.isMultipleSchemasEnabled();

this.setMessage(ActionResult.SUCCESS, "administration.configurations.save.success");

this.json.put("reload", multiSchemaBefore != multiSchemaAfter);
}

public void ignoreUpdate(ExtendedRequest request, ExtendedResponse response) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/biblivre/core/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ public class Constants {

public static final Unit<Length> USER_UNIT = MetricPrefix.CENTI(Units.METRE).multiply(2.54).divide(72);
public static final Function<Quantity<Length>, Float> FROM_CM = q -> q.to(USER_UNIT).getValue().floatValue();

public static final String JSON_EMPTY_OBJECT_STR = "{}";
}
5 changes: 2 additions & 3 deletions src/main/java/biblivre/marc/MarcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ public static Record jsonToRecord(JSONObject json, MaterialType materialType, Re
}

MarcFactory factory = MarcFactory.newInstance();

Leader leader = MarcUtils.createLeader(strLeader, materialType, status);
record = factory.newRecord(leader);
Iterator<String> dataFieldsIterator = json.keys();

Iterator<String> dataFieldsIterator = json.sortedKeys();
while (dataFieldsIterator.hasNext()) {
String dataFieldTag = dataFieldsIterator.next();

Expand All @@ -281,7 +280,7 @@ record = factory.newRecord(leader);
df.setIndicator1(' ');
df.setIndicator2(' ');

Iterator<String> dfIterator = subFieldJson.sortedKeys();
Iterator<String> dfIterator = subFieldJson.keys();
while (dfIterator.hasNext()) {
String subFieldTag = dfIterator.next();

Expand Down
Loading

0 comments on commit 065cd9c

Please sign in to comment.