Skip to content

Commit

Permalink
Upgrade apache commons libraries.
Browse files Browse the repository at this point in the history
Add commons-text, the new home for text based functions from
commons-lang.  Update/replace usages of deprecated methods.
  • Loading branch information
stouffers committed Sep 25, 2019
1 parent c833653 commit 0f1c0fa
Show file tree
Hide file tree
Showing 39 changed files with 120 additions and 111 deletions.
15 changes: 11 additions & 4 deletions pom.xml
Expand Up @@ -104,9 +104,11 @@

<properties>
<c3p0.version>0.9.5.3</c3p0.version>
<commons-cli.version>1.2</commons-cli.version>
<commons-io.version>2.4</commons-io.version>
<commons-lang.version>3.3.2</commons-lang.version>
<commons-cli.version>1.4</commons-cli.version>
<commons-io.version>2.6</commons-io.version>
<commons-lang.version>3.9</commons-lang.version>
<commons-text.version>1.8</commons-text.version>
<commons-validator.version>1.6</commons-validator.version>
<eh-cache.version>2.8.3</eh-cache.version>
<elasticsearch.version>7.0.0</elasticsearch.version>
<flying-saucer.version>9.1.16</flying-saucer.version>
Expand Down Expand Up @@ -339,9 +341,14 @@
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
<version>${commons-validator.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>

<!-- Unit Testing -->

Expand Down
Expand Up @@ -4,7 +4,7 @@
import com.google.common.base.Objects;
import gov.nysenate.openleg.client.view.base.ViewObject;
import gov.nysenate.openleg.model.bill.BillStatus;
import org.apache.commons.lang3.text.WordUtils;
import org.apache.commons.text.WordUtils;

import java.time.LocalDate;
public class BillStatusView implements ViewObject
Expand Down
Expand Up @@ -2,7 +2,7 @@

import gov.nysenate.openleg.client.view.base.ViewObject;
import gov.nysenate.openleg.model.entity.CommitteeId;
import org.apache.commons.lang3.text.WordUtils;
import org.apache.commons.text.WordUtils;

public class CommitteeIdView implements ViewObject {

Expand Down
Expand Up @@ -2,12 +2,8 @@

import gov.nysenate.openleg.client.view.base.ViewObject;
import gov.nysenate.openleg.model.updates.UpdateDigest;
import gov.nysenate.openleg.util.DateUtils;
import org.apache.commons.lang3.text.WordUtils;
import org.apache.commons.text.WordUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.HashMap;
import java.util.Map;

Expand Down
Expand Up @@ -3,17 +3,16 @@

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketsConfig extends AbstractWebSocketMessageBrokerConfigurer
public class WebSocketsConfig implements WebSocketMessageBrokerConfigurer
{
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
super.configureMessageBroker(registry);
registry.enableSimpleBroker("/event");
registry.setApplicationDestinationPrefixes("/app");
}
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.google.common.collect.ImmutableMap;
import gov.nysenate.openleg.client.response.base.BaseResponse;
import gov.nysenate.openleg.client.response.base.ListViewResponse;
import gov.nysenate.openleg.client.response.base.SimpleResponse;
import gov.nysenate.openleg.client.response.base.ViewObjectResponse;
import gov.nysenate.openleg.client.response.error.ErrorCode;
Expand All @@ -16,17 +15,12 @@
import gov.nysenate.openleg.model.auth.AdminUser;
import gov.nysenate.openleg.service.auth.AdminUserService;
import gov.nysenate.openleg.service.auth.InvalidUsernameException;
import gov.nysenate.openleg.service.auth.OpenLegRole;
import gov.nysenate.openleg.service.mail.SendMailService;
import gov.nysenate.openleg.util.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.mindrot.jbcrypt.BCrypt;
import org.slf4j.Logger;
Expand Down Expand Up @@ -216,8 +210,8 @@ private String getSubjectUsername() {
* @param password the password of the new user
*/
@Async
private void sendNewUserEmail(String username, String password) {
String message = StrSubstitutor.replace(registrationEmailTemplate,
protected void sendNewUserEmail(String username, String password) {
String message = StringSubstitutor.replace(registrationEmailTemplate,
ImmutableMap.of("username", username, "password", password, "base_url", environment.getUrl()));
sendMailService.sendMessage(username, registrationEmailSubject, message);
}
Expand Down
Expand Up @@ -119,7 +119,7 @@ public BaseResponse getVariables(@RequestParam(defaultValue = "") String[] varNa
variables.stream()
.filter(var -> !mutableOnly || var.isMutable())
.sorted((a, b) -> ComparisonChain.start()
.compare(a.isMutable(), b.isMutable())
.compareFalseFirst(a.isMutable(), b.isMutable())
.compare(a.getName(), b.getName())
.result())
.collect(Collectors.toList())));
Expand Down
Expand Up @@ -8,7 +8,7 @@
import gov.nysenate.openleg.dao.base.PaginatedList;
import gov.nysenate.openleg.model.agenda.AgendaId;
import gov.nysenate.openleg.service.spotcheck.openleg.JsonOpenlegDaoUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -37,7 +37,7 @@ public JsonOpenlegAgendaDao(JsonOpenlegDaoUtils jsonOpenlegDaoUtils) {
public List<AgendaView> getAgendaViews(int year) {

final String agendasForYearUri =
StrSubstitutor.replace(agendasForYearUriTemplate, ImmutableMap.of("year", year));
StringSubstitutor.replace(agendasForYearUriTemplate, ImmutableMap.of("year", year));
PaginatedList<AgendaSummaryView> agendaSummaries =
jsonOpenlegDaoUtils.queryForViewObjects(AgendaSummaryView.class, agendasForYearUri, LimitOffset.ALL);

Expand All @@ -54,7 +54,7 @@ public AgendaView getAgendaView(AgendaId agendaId) {
"year", agendaId.getYear(),
"agendaNo", agendaId.getNumber()
);
final String agendaUri = StrSubstitutor.replace(getAgendaUriTemplate, subMap);
final String agendaUri = StringSubstitutor.replace(getAgendaUriTemplate, subMap);
return jsonOpenlegDaoUtils.queryForViewObject(AgendaView.class, agendaUri);
}
}
4 changes: 2 additions & 2 deletions src/main/java/gov/nysenate/openleg/dao/base/SqlBaseDao.java
Expand Up @@ -8,7 +8,7 @@
import gov.nysenate.openleg.model.sourcefiles.LegDataFragment;
import gov.nysenate.openleg.model.updates.UpdateType;
import gov.nysenate.openleg.util.DateUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.postgresql.util.PGInterval;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -114,7 +114,7 @@ protected static void setModPubDatesFromResultSet(BaseLegislativeContent obj, Re
protected static String queryReplace(String originalQuery, String key, String replacement) {
Map<String, String> replaceMap = new HashMap<>();
replaceMap.put(key, replacement);
return new StrSubstitutor(replaceMap).replace(originalQuery);
return new StringSubstitutor(replaceMap).replace(originalQuery);
}

/** --- PostgreSQL Hstore handling methods --- */
Expand Down
Expand Up @@ -2,7 +2,7 @@

import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;

import java.util.HashMap;
import java.util.List;
Expand All @@ -25,7 +25,7 @@ public abstract class SqlQueryUtils
public static String getSqlWithSchema(String sql, String schema) {
Map<String, String> replaceMap = new HashMap<>();
replaceMap.put("schema", schema);
return new StrSubstitutor(replaceMap).replace(sql);
return new StringSubstitutor(replaceMap).replace(sql);
}

/**
Expand All @@ -35,7 +35,7 @@ public static String getSqlWithSchema(String sql, String dataSchema, String sear
Map<String, String> replaceMap = new HashMap<>();
replaceMap.put("schema", dataSchema);
replaceMap.put("search_schema", searchSchema);
return new StrSubstitutor(replaceMap).replace(sql);
return new StringSubstitutor(replaceMap).replace(sql);
}

/**
Expand Down
Expand Up @@ -20,7 +20,7 @@
import gov.nysenate.openleg.service.bill.data.VetoDataService;
import gov.nysenate.openleg.service.bill.data.VetoNotFoundException;
import gov.nysenate.openleg.service.entity.member.data.MemberService;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -1058,6 +1058,6 @@ private String applyFullTextFields(String queryTemplate, Set<BillTextFormat> ful
.map(field -> ", " + field)
.collect(Collectors.joining());
final ImmutableMap<String, String> subMap = ImmutableMap.of("fullTextFields", fullTextFields);
return StrSubstitutor.replace(queryTemplate, subMap);
return StringSubstitutor.replace(queryTemplate, subMap);
}
}
Expand Up @@ -7,7 +7,7 @@
import gov.nysenate.openleg.dao.base.PaginatedList;
import gov.nysenate.openleg.model.base.SessionYear;
import gov.nysenate.openleg.service.spotcheck.openleg.JsonOpenlegDaoUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -38,6 +38,6 @@ public PaginatedList<BillView> getBillViews(SessionYear sessionYear, LimitOffset
}

private String getSessionUri(SessionYear sessionYear) {
return StrSubstitutor.replace(getBillsForSessionUriTemplate, ImmutableMap.of("session", sessionYear));
return StringSubstitutor.replace(getBillsForSessionUriTemplate, ImmutableMap.of("session", sessionYear));
}
}
Expand Up @@ -11,7 +11,7 @@
import gov.nysenate.openleg.util.SenateSiteDumpFragParser;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -112,15 +112,15 @@ private SenateSiteDumpFragment getFragmentFromFile(File fragFile) throws IOExcep
* @return String - the prefix that is used for all dump fragments of the designated dump
*/
private static String getDumpFragFilenamePrefix(SenateSiteDumpFragment fragment) {
return StrSubstitutor.replace(dumpFragFilenamePrefix(fragment.getDumpId().getRefType()), getDumpIdSubMap(fragment.getDumpId()));
return StringSubstitutor.replace(dumpFragFilenamePrefix(fragment.getDumpId().getRefType()), getDumpIdSubMap(fragment.getDumpId()));
}

/**
* @param fragment SenateSiteDumpFragment
* @return String - the filename that is used for the designated dump fragment
*/
private static String getDumpFragFilename(SenateSiteDumpFragment fragment) {
return StrSubstitutor.replace(dumpFragFilename(fragment.getDumpId().getRefType()), getDumpFragSubMap(fragment));
return StringSubstitutor.replace(dumpFragFilename(fragment.getDumpId().getRefType()), getDumpFragSubMap(fragment));
}

private static ImmutableMap<String, String> getDumpIdSubMap(SenateSiteDumpId dumpId) {
Expand Down Expand Up @@ -159,7 +159,7 @@ private static String dumpFragFilename(SpotCheckRefType refType) {
/** Regex to match SenateSiteDumpFragments of the given refType. */
private static Pattern dumpFragFilenameRegex(SpotCheckRefType refType) {
String reTemplate = "^" + dumpFragFilename(refType);
String regex = StrSubstitutor.replace(reTemplate, ImmutableMap.of(
String regex = StringSubstitutor.replace(reTemplate, ImmutableMap.of(
"year", "(\\d{4})",
"refDateTime", "(" + BASIC_ISO_DATE_TIME_REGEX.toString() + ")",
"seqNo", "(\\d+)"));
Expand Down
Expand Up @@ -12,7 +12,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void saveScrapedBillContent(String content, BaseBillId scrapedBill) throw
}

private File createScrapeFile(File stagingDir, BaseBillId baseBillId) {
String file = StrSubstitutor.replace(FILE_TEMPLATE, ImmutableMap.<String, String>builder()
String file = StringSubstitutor.replace(FILE_TEMPLATE, ImmutableMap.<String, String>builder()
.put("sessionYear", Integer.toString(baseBillId.getSession().getYear()))
.put("printNo", baseBillId.getPrintNo())
.put("scrapedTime", LocalDateTime.now().format(DateUtils.BASIC_ISO_DATE_TIME))
Expand Down
Expand Up @@ -5,7 +5,7 @@
import gov.nysenate.openleg.controller.api.base.BaseCtrl;
import gov.nysenate.openleg.dao.base.LimitOffset;
import gov.nysenate.openleg.service.spotcheck.openleg.JsonOpenlegDaoUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,7 +29,7 @@ public JsonOpenlegCalendarDao(JsonOpenlegDaoUtils jsonOpenlegDaoUtils) {

@Override
public List<CalendarView> getCalendarViews(int year) {
final String getCalsUri = StrSubstitutor.replace(getCalendarsUriTemplate, ImmutableMap.of("year", year));
final String getCalsUri = StringSubstitutor.replace(getCalendarsUriTemplate, ImmutableMap.of("year", year));
return jsonOpenlegDaoUtils.queryForViewObjects(CalendarView.class, getCalsUri, LimitOffset.ALL).getResults();
}
}
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -115,7 +116,7 @@ protected Document getJsoupDocument(String url) {

protected String getUrlContents(URL url) {
try {
return IOUtils.toString(url);
return IOUtils.toString(url, Charset.defaultCharset());
} catch (IOException ex) {
throw new ScrapingException(url, ex);
}
Expand Down
Expand Up @@ -5,7 +5,7 @@
import gov.nysenate.openleg.model.updates.UpdateContentType;
import gov.nysenate.openleg.model.updates.UpdateReturnType;
import gov.nysenate.openleg.model.updates.UpdateType;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.text.StringSubstitutor;

import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -135,7 +135,7 @@ public static String buildQuery(String schema, LimitOffset limOff, SortOrder ord
.putAll(getColumnReplaceMap(returnType))
.put("dateColumn", updateType == UpdateType.PROCESSED_DATE ? "action_date_time" : "published_date_time")
.build();
aggregateQuery = StrSubstitutor.replace(aggregateQuery, replaceMap);
aggregateQuery = StringSubstitutor.replace(aggregateQuery, replaceMap);
return aggregateQuery;
}

Expand Down
Expand Up @@ -70,8 +70,8 @@ public String toString() {
public int compareTo(PublishStatus o) {
return ComparisonChain.start()
.compare(this.effectDateTime, o.effectDateTime)
.compare(this.override, o.override)
.compare(this.published, o.published)
.compareFalseFirst(this.override, o.override)
.compareFalseFirst(this.published, o.published)
.result();
}

Expand Down
Expand Up @@ -2,7 +2,7 @@

import com.google.common.collect.SortedSetMultimap;
import gov.nysenate.openleg.model.bill.BillVoteCode;
import org.apache.commons.lang3.text.WordUtils;
import org.apache.commons.text.WordUtils;

import java.time.LocalDate;
import java.util.Objects;
Expand Down
Expand Up @@ -8,6 +8,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -85,7 +86,7 @@ private LocalDate getReportDateFromFileName() {
@JsonIgnore
public String getText() {
try {
return FileUtils.readFileToString(file);
return FileUtils.readFileToString(file, Charset.defaultCharset());
}
catch (IOException e) {
throw new RuntimeException("Failed to read text from Daybreak file:" + this.toString());
Expand Down
Expand Up @@ -11,6 +11,7 @@
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.charset.Charset;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand Down Expand Up @@ -44,7 +45,8 @@ public class PublicHearingParser
* @throws IOException
*/
public void process(PublicHearingFile publicHearingFile) throws IOException {
final List<List<String>> pages = PublicHearingTextUtils.getPages(FileUtils.readFileToString(publicHearingFile.getFile()));
final List<List<String>> pages = PublicHearingTextUtils.getPages(
FileUtils.readFileToString(publicHearingFile.getFile(), Charset.defaultCharset()));
final List<String> firstPage = pages.get(0);

String title = titleParser.parse(firstPage);
Expand Down

0 comments on commit 0f1c0fa

Please sign in to comment.