Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Sep 13, 2020
1 parent ff5dcc1 commit 2aac2b6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/edu/harvard/mcz/precapture/data/UnitTrayLabel.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<column name="Tribe" length="40"/>
</property>
<property name="scientificName" type="string">
<column name="ScientificName" length="512" />
<column name="ScientificName" length="512"/>
</property>
<property name="genus" type="string">
<column name="Genus" length="40" index="utl_genus_idx"/>
Expand Down
38 changes: 19 additions & 19 deletions src/edu/harvard/mcz/precapture/data/UnitTrayLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class UnitTrayLabel implements TaxonNameReturner {
private String family;
private String subfamily;
private String tribe;
private String scientificName;
private String scientificName;
private String genus;
private String specificEpithet;
private String subspecificEpithet;
Expand Down Expand Up @@ -312,23 +312,23 @@ public void setTribe(String tribe) {
}
}

/**
* @return the scientificName
*/
public String getScientificName() {
if (this.scientificName != null && !this.scientificName.trim().equals("")) {
/**
* @return the scientificName
*/
public String getScientificName() {
if (this.scientificName != null && !this.scientificName.trim().equals("")) {
return scientificName;
}
this.scientificName = UnitTrayLabelLifeCycle.getScientificName(this);
return this.scientificName;
}
this.scientificName = UnitTrayLabelLifeCycle.getScientificName(this);
return this.scientificName;
}

/**
* @param scientificName the scientificName to set
*/
public void setScientificName(String scientificName) {
this.scientificName = scientificName;
}
/**
* @param scientificName the scientificName to set
*/
public void setScientificName(String scientificName) {
this.scientificName = scientificName;
}

/**
* @return the genus
Expand Down Expand Up @@ -535,14 +535,14 @@ public void setIdentifiedBy(String identifiedBy) {
this.identifiedBy = identifiedBy;
}

public void setIdentifiedDate(String identifiedDate) {
this.identifiedDate = identifiedDate;
}

public String getIdentifiedDate() {
return identifiedDate;
}

public void setIdentifiedDate(String identifiedDate) {
this.identifiedDate = identifiedDate;
}

/**
* @return the ordinal
*/
Expand Down
31 changes: 10 additions & 21 deletions src/edu/harvard/mcz/precapture/encoder/LabelEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
import boofcv.alg.fiducial.qrcode.QrCodeEncoder;
import boofcv.alg.fiducial.qrcode.QrCodeGeneratorImage;
import boofcv.io.image.ConvertBufferedImage;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.*;
Expand All @@ -41,7 +35,6 @@
import edu.harvard.mcz.precapture.exceptions.BarcodeCreationException;
import edu.harvard.mcz.precapture.exceptions.PrintFailedException;
import edu.harvard.mcz.precapture.ui.ContainerLabel;
import edu.harvard.mcz.precapture.utils.GZipCompressor;
import edu.harvard.mcz.precapture.xml.labels.LabelDefinitionListType;
import edu.harvard.mcz.precapture.xml.labels.LabelDefinitionType;
import org.apache.commons.logging.Log;
Expand All @@ -50,14 +43,13 @@
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPOutputStream;

/**
* LabelEncoder
Expand Down Expand Up @@ -417,22 +409,19 @@ private QrCode getQRCodeMatrix() throws WriterException {
break;
}
String data = label.toJSON();
boolean compress = false;
if (compress) {
byte[] compressedStrBytes = data.getBytes(StandardCharsets.UTF_8);
// compress message

byte[] compressedStrBytes = data.getBytes(StandardCharsets.UTF_8);
// compress message
// try {
// compressedStrBytes = GZipCompressor.compress(data);
// } catch (IOException e) {
// // fallback to uncompressed
// log.error("Failed to compress: " + e.getMessage());
// log.error(e);
// }
// add the bytes to the QR Code
qr_writer.addBytes(compressedStrBytes);
} else {
qr_writer.addAutomatic(data);
}
// add the bytes to the QR Code
qr_writer.addBytes(compressedStrBytes);

return qr_writer.fixate();
}

Expand All @@ -442,7 +431,7 @@ public BufferedImage getBufferedImage() throws WriterException {
render.render(getQRCodeMatrix());

// Convert it to a BufferedImage for display purposes
return ConvertBufferedImage.convertTo(render.getGray(),null);
return ConvertBufferedImage.convertTo(render.getGray(), null);
}

public Image getImage() throws BarcodeCreationException {
Expand Down
14 changes: 3 additions & 11 deletions src/edu/harvard/mcz/precapture/test/TestLabelEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@
*/
package edu.harvard.mcz.precapture.test;

import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.common.BitMatrix;
import com.itextpdf.text.pdf.qrcode.ByteMatrix;
import edu.harvard.mcz.precapture.PreCaptureApp;
import edu.harvard.mcz.precapture.PreCaptureProperties;
import edu.harvard.mcz.precapture.PreCaptureSingleton;
import edu.harvard.mcz.precapture.decoder.LabelDecoder;
import edu.harvard.mcz.precapture.encoder.LabelEncoder;
import edu.harvard.mcz.precapture.ui.ContainerLabel;
import edu.harvard.mcz.precapture.ui.FieldPlusText;
import edu.harvard.mcz.precapture.utils.GZipCompressor;
import edu.harvard.mcz.precapture.xml.Field;
import edu.harvard.mcz.precapture.xml.MappingList;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
Expand All @@ -45,14 +39,12 @@
import javax.xml.bind.Unmarshaller;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.zip.DeflaterOutputStream;
import java.util.Map;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down
6 changes: 3 additions & 3 deletions src/edu/harvard/mcz/precapture/utils/GZipCompressor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package edu.harvard.mcz.precapture.utils;

import edu.harvard.mcz.precapture.decoder.LabelDecoder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

Expand All @@ -18,7 +18,7 @@ public static byte[] compress(final String str) throws IOException {
}
ByteArrayOutputStream obj = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(obj);
gzip.write(str.getBytes("UTF-8"));
gzip.write(str.getBytes(StandardCharsets.UTF_8));
gzip.flush();
gzip.close();
return obj.toByteArray();
Expand All @@ -31,7 +31,7 @@ public static String decompress(final byte[] compressed) throws IOException {
}
if (isCompressed(compressed)) {
final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed));
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gis, StandardCharsets.UTF_8));

String line;
while ((line = bufferedReader.readLine()) != null) {
Expand Down

0 comments on commit 2aac2b6

Please sign in to comment.