Skip to content

Commit

Permalink
Various code smell fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed May 29, 2023
1 parent 804b853 commit 2b42f2e
Show file tree
Hide file tree
Showing 335 changed files with 2,523 additions and 2,588 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected String getLatestChangeLogToken(String repositoryId) throws Persistence
return "0";
} else {
log.debug("latestDate.getTime(): {}", latestDate != null ? latestDate.getTime() : "");
log.debug("latestFolderDate.getTime(): {}", latestDate != null ? latestFolderDate.getTime() : "");
log.debug("latestFolderDate.getTime(): {}", latestFolderDate != null ? latestFolderDate.getTime() : "");
Timestamp myDate = getLatestTimestamp(latestDate, latestFolderDate);

log.debug("myDate.getTime(): {}", myDate.getTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ public String queryForString(String sql) throws PersistenceException {
} catch (EmptyResultDataAccessException e) {
return null;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new PersistenceException(e);
}
}
Expand Down
10 changes: 6 additions & 4 deletions logicaldoc-core/src/main/java/com/logicaldoc/core/RunLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;

import org.java.plugin.registry.Extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.logicaldoc.util.Context;
import com.logicaldoc.util.config.ContextProperties;
Expand All @@ -22,22 +24,22 @@
public enum RunLevel {
DEFAULT("default"), BULKLOAD("bulkload"), DEVEL("devel"), DEMO("demo"), UPDATED("updated"), SLAVE("slave");

private static Logger log = LoggerFactory.getLogger(RunLevel.class);

private String level;

RunLevel(String level) {
this.level = level;
}


@Override
public String toString() {
return this.level;
}

public static RunLevel current() {
ContextProperties config = getConfig();
String runLevel = config != null ? config.getProperty("runlevel", DEFAULT.toString())
: DEFAULT.toString();
String runLevel = config != null ? config.getProperty("runlevel", DEFAULT.toString()) : DEFAULT.toString();
return RunLevel.fromString(runLevel);
}

Expand Down Expand Up @@ -79,7 +81,7 @@ private static ContextProperties getConfig() {
try {
conf = new ContextProperties();
} catch (IOException e) {
System.out.println(e.getMessage());
log.error(e.getMessage(), e);
}
return conf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ public List<Hit> search(long tenantId, String expression, List<String> filters,
hitsIdsCondition.append(")");
}

StringBuilder richQuery = new StringBuilder();
// Find real documents
richQuery = new StringBuilder(
StringBuilder richQuery = new StringBuilder(
"select A.ld_id, A.ld_customid, A.ld_docref, A.ld_type, A.ld_version, A.ld_lastmodified, ");
richQuery
.append(" A.ld_date, A.ld_publisher, A.ld_creation, A.ld_creator, A.ld_filesize, A.ld_immutable, ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ public void send(EMail email) throws MessagingException {
Transport trans = buildTransport(sess);

Address[] adr = message.getAllRecipients();
// message.setSentDate(new Date());

MailDateFormat formatter = new MailDateFormat();
formatter.setTimeZone(TimeZone.getTimeZone("GMT")); // always use UTC
Expand Down Expand Up @@ -432,7 +431,6 @@ private Properties prepareMailSessionProperties() {
props.put("mail.smtp.ssl.protocols", "TLSv1.1 TLSv1.2");
props.put("mail.smtp.ssl.checkserveridentity", "false");
props.put("mail.smtp.ssl.trust", "*");
// props.put("mail.debug", "true");
return props;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,15 @@ private static void copyMetadata(EMail email, com.auxilii.msgparser.Message msg)
rec.setType(Recipient.TYPE_EMAIL);
email.getRecipients().add(rec);

if (StringUtils.isEmpty(email.getMessageText()))
if (StringUtils.isNotEmpty(msg.getBodyRTF())) {
email.setMessageText(msg.getBodyRTF());
email.setHtml(0);
}
if (StringUtils.isEmpty(email.getMessageText()) && StringUtils.isNotEmpty(msg.getBodyRTF())) {
email.setMessageText(msg.getBodyRTF());
email.setHtml(0);
}

if (StringUtils.isEmpty(email.getMessageText()))
if (StringUtils.isNotEmpty(msg.getBodyText())) {
email.setMessageText(msg.getBodyText());
email.setHtml(0);
}
if (StringUtils.isEmpty(email.getMessageText()) && StringUtils.isNotEmpty(msg.getBodyText())) {
email.setMessageText(msg.getBodyText());
email.setHtml(0);
}

List<RecipientEntry> recs = msg.getCcRecipients();
for (RecipientEntry entry : recs) {
Expand Down Expand Up @@ -260,7 +258,6 @@ public static MimeMessage readMime(InputStream is) throws MessagingException {
props.put("mail.smtp.provider.class", CustomTransport.class.getName());
props.put("mail.smtp.provider.vendor", "foo");
props.put("mail.smtp.provider.version", "0.0.0");
// props.put("mail.host", "smtp.unexisting.com");

try {
Session mailSession = Session.getInstance(props, null);
Expand Down Expand Up @@ -366,7 +363,7 @@ private static void setReplyTo(javax.mail.Message msg, EMail email) throws Messa
return rec;
}).collect(Collectors.toSet()));
} catch (Exception t) {
log.warn("Unable to extract BCC addresses - %s", t.getMessage());
log.warn("Unable to extract BCC addresses {}", t.getMessage());
}
}
}
Expand All @@ -384,7 +381,7 @@ private static void setBCC(javax.mail.Message msg, EMail email) throws Messaging
return rec;
}).collect(Collectors.toSet()));
} catch (Exception t) {
log.warn("Unable to extract BCC addresses - %s", t.getMessage());
log.warn("Unable to extract BCC addresses {}", t.getMessage());
}
}
}
Expand All @@ -402,7 +399,7 @@ private static void setCC(javax.mail.Message msg, EMail email) throws MessagingE
return rec;
}).collect(Collectors.toSet()));
} catch (Exception t) {
log.warn("Unable to extract CC addresses - %s", t.getMessage());
log.warn("Unable to extract CC addresses {}", t.getMessage());
}
}
}
Expand All @@ -420,7 +417,7 @@ private static void setTO(javax.mail.Message msg, EMail email) throws MessagingE
return rec;
}).collect(Collectors.toSet()));
} catch (Exception t) {
log.warn("Unable to extract TO addresses - %s", t.getMessage());
log.warn("Unable to extract TO addresses {}", t.getMessage());
}
}
}
Expand Down Expand Up @@ -554,7 +551,7 @@ private static String getText(Part p) throws MessagingException, IOException {
*/
private static String extractTextFromTextStar(Part p) throws IOException, MessagingException {
Object obj = p.getContent();
String str = NO_BODY;
String str;

if (obj instanceof InputStream) {
InputStream is = (InputStream) obj;
Expand Down Expand Up @@ -586,7 +583,6 @@ private static String extractTextFromMultipartAlernative(Part p) throws IOExcept
// prefer html over plain text
Multipart mp = (Multipart) p.getContent();
String text = "T" + NO_BODY;
// log.info("Mime Parts: {}", mp.getCount());

for (int i = 0; i < mp.getCount(); i++) {
Part bp = mp.getBodyPart(i);
Expand Down Expand Up @@ -759,10 +755,9 @@ private static void extractPartText(Object content, StringBuilder textBody) thro
String disposition = part.getDisposition();
String contentType = part.getContentType();

if ((disposition == null || "inline".equals(disposition)) && contentType != null) {
if (contentType.toLowerCase().startsWith("text/plain")) {
textBody.append(part.getContent());
}
if ((disposition == null || "inline".equals(disposition)) && contentType != null
&& contentType.toLowerCase().startsWith("text/plain")) {
textBody.append(part.getContent());
}
return;
}
Expand Down Expand Up @@ -799,7 +794,6 @@ public CustomTransport(Session smtpSession, URLName urlName) {
@Override
public void sendMessage(Message message, Address[] addresses) throws MessagingException {
// Take the message and write it somewhere
// e.g.: a logger or an OutputStream message.writeTo(...);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.logicaldoc.util.io.FileUtil;

/**
* A base class for those converters that operate on comressed archives
* A base class for those converters that operate on compressed archives
*
* @author Marco Meschieri - LogicalDOC
* @since 8.8.3
Expand All @@ -23,7 +23,7 @@ public abstract class CompressedArchiveConverter extends AbstractFormatConverter

protected static Logger log = LoggerFactory.getLogger(CompressedArchiveConverter.class);

protected void convertMultipleEntries(String sid, Document document, File src, File dest, List<String> entries)
protected void convertMultipleEntries(String sid, Document document, File dest, List<String> entries)
throws IOException {
File tempFile = FileUtil.createTempFile("zipconvert", ".txt");
try (FileWriter writer = new FileWriter(tempFile);) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,19 +434,19 @@ public FormatConverter getConverter(String inFileName, String outFileName) {

String inOutkey = composeKey(inFileName, outFileName);

List<FormatConverter> converters = getConverters().get(inOutkey);
if (converters == null || converters.isEmpty())
converters = getConverters().get("*-pdf");
if (converters == null || converters.isEmpty())
log.warn("No format converter for file " + inFileName);
List<FormatConverter> convrters = getConverters().get(inOutkey);
if (convrters == null || convrters.isEmpty())
convrters = getConverters().get("*-pdf");
if (convrters == null || convrters.isEmpty())
log.warn("No format converter for file {}", inFileName);

// Get the first available converter
FormatConverter converter = converters != null ? converters.get(0) : null;
FormatConverter converter = convrters != null ? convrters.get(0) : null;

// Check if a special binding is configured
String currentConverter = config.getProperty("converter." + inOutkey);
if (StringUtils.isNotEmpty(currentConverter))
for (FormatConverter formatConverter : converters) {
for (FormatConverter formatConverter : convrters) {
if (formatConverter.getClass().getName().equals(currentConverter)) {
converter = formatConverter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ else if ("png".equals(ext)) {
else if ("eps".equals(ext))
device = "eps2write ";

int timeout = 30;
try {
timeout = Integer.parseInt(getParameter("timeout"));
} catch (Exception t) {
// Nothing to do
}
int timeout = getTimeout();

String arguments = getParameter("arguments");
String commandLine = getParameter("path") + " " + (arguments != null ? arguments : "") + " -sDEVICE="
Expand All @@ -63,6 +58,16 @@ else if ("eps".equals(ext))
}
}

private int getTimeout() {
int timeout = 30;
try {
timeout = Integer.parseInt(getParameter("timeout"));
} catch (Exception t) {
// Nothing to do
}
return timeout;
}

@Override
public List<String> getParameterNames() {
return Arrays.asList("path", "arguments", "timeout");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ public void internalConvert(String sid, Document document, File src, File dest)
throw new IOException("Unable to convert image to " + ext);

try {
int timeout = 10;
try {
timeout = Integer.parseInt(getParameter("timeout"));
} catch (Exception t) {
// Nothing to do
}
int timeout = getTimeout();

String commandLine = getParameter("path") + " -compress JPEG " + src.getPath() + " " + dest.getPath();
new Exec().exec(commandLine, null, null, timeout);
Expand All @@ -48,6 +43,16 @@ public void internalConvert(String sid, Document document, File src, File dest)
}
}

private int getTimeout() {
int timeout = 10;
try {
timeout = Integer.parseInt(getParameter("timeout"));
} catch (Exception t) {
// Nothing to do
}
return timeout;
}

@Override
public List<String> getParameterNames() {
return Arrays.asList("path", "timeout");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class RarConverter extends CompressedArchiveConverter {
public void internalConvert(String sid, Document document, File src, File dest) throws IOException {
List<String> entries = new RarUtil().listEntries(src);
if (entries.size() > 1)
convertMultipleEntries(sid, document, src, dest, entries);
convertMultipleEntries(sid, document, dest, entries);
else
convertSingleEntry(sid, document, src, dest, entries.get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SevenZipConverter extends CompressedArchiveConverter {
public void internalConvert(String sid, Document document, File src, File dest) throws IOException {
List<String> entries = new SevenZipUtil().listEntries(src);
if (entries.size() > 1)
convertMultipleEntries(sid, document, src, dest, entries);
convertMultipleEntries(sid, document, dest, entries);
else
convertSingleEntry(sid, document, src, dest, entries.get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class TarConverter extends CompressedArchiveConverter {
public void internalConvert(String sid, Document document, File src, File dest) throws IOException {
List<String> entries = new TarUtil().listEntries(src);
if (entries.size() > 1)
convertMultipleEntries(sid, document, src, dest, entries);
convertMultipleEntries(sid, document, dest, entries);
else
convertSingleEntry(sid, document, src, dest, entries.get(0));
}

@Override
protected void extractEntry(File archiveFile, String entry, File uncompressedEntryFile) throws IOException {
new TarUtil().extractEntry(archiveFile, entry, uncompressedEntryFile);
new TarUtil().extractEntry(archiveFile, uncompressedEntryFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,9 @@ private Map<String, String> loadStyleSheets() {
if (StringUtils.isNotEmpty(value)) {
String[] styles = value.split("\\,");
for (String style : styles) {
if (StringUtils.isNoneEmpty(style)) {
if (style.contains("|")) {
String[] tokens = style.trim().split("\\|");
map.put(tokens[0].trim(), tokens[1].trim());
}
if (StringUtils.isNoneEmpty(style) && style.contains("|")) {
String[] tokens = style.trim().split("\\|");
map.put(tokens[0].trim(), tokens[1].trim());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void convertZip(String sid, Document document, File src, File dest) thro
ZipUtil zipUtil = new ZipUtil();
List<String> entries = zipUtil.listEntries(src);
if (entries.size() > 1)
convertMultipleEntries(sid, document, src, dest, entries);
convertMultipleEntries(sid, document, dest, entries);
else
convertSingleEntry(sid, document, src, dest, entries.get(0));

Expand Down
Loading

0 comments on commit 2b42f2e

Please sign in to comment.