use of org.codice.imaging.nitf.core.tre.impl.TreEntryImpl in project alliance by codice.
the class TreUtilityTest method createMtirpbTre.
public static Tre createMtirpbTre() throws NitfFormatException {
final String[] fieldNames = { "MTI_DP", "MTI_PACKET_ID", "PATCH_NO", "WAMTI_FRAME_NO", "WAMTI_BAR_NO", "DATIME", "ACFT_LOC", "ACFT_ALT", "ACFT_ALT_UNIT", "ACFT_HEADING", "MTI_LR", "SQUINT_ANGLE", "COSGRZ", "NO_VALID_TARGETS" };
final String[] values = { "00", "001", "0001", "00001", "1", "20141108235219", "+52.123456-004.123456", "150000", "m", "000", " ", " ", "0.03111", "001" };
StringBuilder accumulator = new StringBuilder();
Tre tre = mock(Tre.class);
when(tre.getName()).thenReturn("MTIRPB");
for (int i = 0; i < fieldNames.length; i++) {
accumulator.append(values[i]);
when(tre.getEntry(fieldNames[i])).thenReturn(new TreEntryImpl(fieldNames[i], values[i], "string"));
}
TreGroup targetsGroup = createTreGroup(accumulator);
TreEntryImpl targetsEntry = new TreEntryImpl("TARGETS");
targetsEntry.addGroup(targetsGroup);
when(tre.getEntry("TARGETS")).thenReturn(targetsEntry);
when(tre.getSource()).thenReturn(TreSource.UserDefinedHeaderData);
when(tre.getRawData()).thenReturn(accumulator.toString().getBytes());
return tre;
}
use of org.codice.imaging.nitf.core.tre.impl.TreEntryImpl in project alliance by codice.
the class TreUtilityTest method testConvertToInteger.
@Test
public void testConvertToInteger() throws NitfFormatException, IOException {
Tre tre = TreFactory.getDefault("TestTre", TreSource.ImageExtendedSubheaderData);
tre.add(new TreEntryImpl("INTEGER_VALID_1", "12345", "UINT"));
tre.add(new TreEntryImpl("INTEGER_VALID_2", "-12345", "UINT"));
tre.add(new TreEntryImpl("INTEGER_VALID_3", "-0120", "UINT"));
tre.add(new TreEntryImpl("INTEGER_INVALID_1", "1.2", "UINT"));
tre.add(new TreEntryImpl("INTEGER_INVALID_2", "-1.3-9", "UINT"));
tre.add(new TreEntryImpl("INTEGER_INVALID_3", "ABCD", "UINT"));
assertThat(TreUtility.convertToInteger(tre, "INTEGER_VALID_1"), is(12345));
assertThat(TreUtility.convertToInteger(tre, "INTEGER_VALID_2"), is(-12345));
assertThat(TreUtility.convertToInteger(tre, "INTEGER_VALID_3"), is(-120));
assertThat(TreUtility.convertToInteger(tre, "INTEGER_INVALID_1"), nullValue());
assertThat(TreUtility.convertToInteger(tre, "INTEGER_INVALID_2"), nullValue());
assertThat(TreUtility.convertToInteger(tre, "INTEGER_INVALID_3"), nullValue());
}
use of org.codice.imaging.nitf.core.tre.impl.TreEntryImpl in project alliance by codice.
the class ImageInputTransformerTest method createNitfWithCsdida.
private static void createNitfWithCsdida(File file) {
NitfHeader header = NitfHeaderFactory.getDefault(FileType.NITF_TWO_ONE);
Tre csdida = TreFactory.getDefault("CSDIDA", TreSource.ExtendedHeaderData);
csdida.add(new TreEntryImpl("DAY", "01", "UINT"));
csdida.add(new TreEntryImpl("MONTH", str(3), "UINT"));
csdida.add(new TreEntryImpl("YEAR", "1234", "UINT"));
csdida.add(new TreEntryImpl("PLATFORM_CODE", "XY", "string"));
csdida.add(new TreEntryImpl("VEHICLE_ID", "01", "string"));
csdida.add(new TreEntryImpl("PASS", "01", "string"));
csdida.add(new TreEntryImpl("OPERATION", "001", "UINT"));
csdida.add(new TreEntryImpl("SENSOR_ID", str(2), "string"));
csdida.add(new TreEntryImpl("PRODUCT_ID", str(2), "string"));
csdida.add(new TreEntryImpl("RESERVED_0", str(4), "string"));
csdida.add(new TreEntryImpl("TIME", "20000202010101", "UINT"));
csdida.add(new TreEntryImpl("PROCESS_TIME", "20000202010101", "UINT"));
csdida.add(new TreEntryImpl("RESERVED_1", str(2), "string"));
csdida.add(new TreEntryImpl("RESERVED_2", str(2), "string"));
csdida.add(new TreEntryImpl("RESERVED_3", str(1), "string"));
csdida.add(new TreEntryImpl("RESERVED_4", str(1), "string"));
csdida.add(new TreEntryImpl("SOFTWARE_VERSION_NUMBER", str(10), "string"));
header.getTREsRawStructure().add(csdida);
new NitfCreationFlowImpl().fileHeader(() -> header).write(file.getAbsolutePath());
}
use of org.codice.imaging.nitf.core.tre.impl.TreEntryImpl in project alliance by codice.
the class ImageInputTransformerTest method createNitfWithPiaprd.
private static Map<NitfAttribute, NitfValue> createNitfWithPiaprd(File file) throws NitfFormatException {
String accessId = "THIS IS AN IPA FILE. -END-";
String keyword = "FIRST " + " " + " " + " " + " -END-";
Tre piaprd = TreFactory.getDefault("PIAPRD", TreSource.ImageExtendedSubheaderData);
piaprd.add(new TreEntryImpl("ACCESSID", accessId, "string"));
piaprd.add(new TreEntryImpl("FMCONTROL", "PXX -END-", "string"));
piaprd.add(new TreEntryImpl("SUBDET", "P", "string"));
piaprd.add(new TreEntryImpl("PRODCODE", "YY", "string"));
piaprd.add(new TreEntryImpl("PRODUCERSE", "UNKNOW", "string"));
piaprd.add(new TreEntryImpl("PRODIDNO", "X211 -END-", "string"));
piaprd.add(new TreEntryImpl("PRODSNME", "JUNK FILE.", "string"));
piaprd.add(new TreEntryImpl("PRODUCERCD", "27", "string"));
piaprd.add(new TreEntryImpl("PRODCRTIME", "26081023ZOCT95", "string"));
piaprd.add(new TreEntryImpl("MAPID", "132 -END-", "string"));
piaprd.add(new TreEntryImpl("SECTITLEREP", "01", "UINT"));
TreEntryImpl secTitleEntry = new TreEntryImpl("SECTITLE", null, "string");
TreGroup secTitleGroup = TreFactory.getDefault("SECTITLE", TreSource.ImageExtendedSubheaderData);
secTitleGroup.getEntries().add(0, new TreEntryImpl("SECTITLE", " -END-", "string"));
secTitleGroup.getEntries().add(1, new TreEntryImpl("PPNUM", "32/47", "string"));
secTitleGroup.getEntries().add(2, new TreEntryImpl("TPP", "001", "UINT"));
secTitleEntry.initGroups();
secTitleEntry.addGroup(secTitleGroup);
piaprd.add(secTitleEntry);
piaprd.add(new TreEntryImpl("REQORGREP", "01", "UINT"));
TreEntryImpl reqorgEntry = new TreEntryImpl("REQORG", null, "string");
TreGroup reqorgGroup = TreFactory.getDefault("REQORG", TreSource.ImageExtendedSubheaderData);
reqorgGroup.getEntries().add(0, new TreEntryImpl("REQORG", "FIRST -END-", "string"));
reqorgEntry.initGroups();
reqorgEntry.addGroup(reqorgGroup);
piaprd.add(reqorgEntry);
piaprd.add(new TreEntryImpl("KEYWORDREP", "01", "UINT"));
TreEntryImpl keywordEntry = new TreEntryImpl("KEYWORD", null, "string");
TreGroup keywordGroup = TreFactory.getDefault("KEYWORD", TreSource.ImageExtendedSubheaderData);
keywordGroup.getEntries().add(0, new TreEntryImpl("KEYWORD", keyword, "string"));
keywordEntry.initGroups();
keywordEntry.addGroup(keywordGroup);
piaprd.add(keywordEntry);
piaprd.add(new TreEntryImpl("ASSRPTREP", "01", "UNIT"));
TreEntryImpl assrptEntry = new TreEntryImpl("ASSRPT", null, "string");
TreGroup asserptGroup = TreFactory.getDefault("ASSRPT", TreSource.ImageExtendedSubheaderData);
asserptGroup.getEntries().add(0, new TreEntryImpl("ASSRPT", "FIRST -END-", "string"));
assrptEntry.initGroups();
assrptEntry.addGroup(asserptGroup);
piaprd.add(assrptEntry);
piaprd.add(new TreEntryImpl("ATEXTREP", "01", "UINT"));
TreEntryImpl atextEntry = new TreEntryImpl("ATEXT", null, "string");
TreGroup atextGroup = TreFactory.getDefault("ATEXT", TreSource.ImageExtendedSubheaderData);
atextGroup.getEntries().add(0, new TreEntryImpl("ATEXT", "FIRST " + " " + " " + " " + " -END-", "string"));
atextEntry.initGroups();
atextEntry.addGroup(atextGroup);
piaprd.add(atextEntry);
ImageSegment imageSegment = TreUtilityTest.createImageSegment();
imageSegment.getTREsRawStructure().add(piaprd);
new NitfCreationFlowImpl().fileHeader(() -> TreUtilityTest.createFileHeader()).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
// key value pair of nitf attributes and expected getAttributes
Map<NitfAttribute, NitfValue> assertMap = new HashMap<>();
assertMap.put(PiaprdAttribute.ACCESS_ID_ATTRIBUTE, new NitfValue(accessId));
assertMap.put(IndexedPiaprdAttribute.KEYWORD_ATTRIBUTE, new NitfValue(keyword));
return assertMap;
}
use of org.codice.imaging.nitf.core.tre.impl.TreEntryImpl in project alliance by codice.
the class ImageInputTransformerTest method createNitfWithExpltb.
private static Map<NitfAttribute, NitfValue> createNitfWithExpltb(File file) {
String angleToNorth = "150.001";
String angleToNorthAccuracy = "03.001";
String mode = "LBM";
String primeId = "aaaaaaaaaaaa";
Tre expltb = TreFactory.getDefault("EXPLTB", TreSource.ImageExtendedSubheaderData);
expltb.add(new TreEntryImpl("ANGLE_TO_NORTH", angleToNorth, "float"));
expltb.add(new TreEntryImpl("ANGLE_TO_NORTH_ACCY", angleToNorthAccuracy, "float"));
expltb.add(new TreEntryImpl("SQUINT_ANGLE", "-59.002", "float"));
expltb.add(new TreEntryImpl("SQUINT_ANGLE_ACCY", "44.002", "float"));
expltb.add(new TreEntryImpl("MODE", mode, "string"));
expltb.add(new TreEntryImpl("GRAZE_ANG", "50.00", "float"));
expltb.add(new TreEntryImpl("GRAZE_ANG_ACCY", "00.01", "float"));
expltb.add(new TreEntryImpl("SLOPE_ANG", "24.00", "float"));
expltb.add(new TreEntryImpl("POLAR", "HH", "UINT"));
expltb.add(new TreEntryImpl("NSAMP", "03333", "UINT"));
expltb.add(new TreEntryImpl("SEQ_NUM", "4", "string"));
expltb.add(new TreEntryImpl("PRIME_ID", primeId, "string"));
expltb.add(new TreEntryImpl("PRIME_BE", "bbbbbbbbbbbbbbb", "string"));
expltb.add(new TreEntryImpl("N_SEC", "11", "UINT"));
expltb.add(new TreEntryImpl("IPR", "22", "UINT"));
ImageSegment imageSegment = TreUtilityTest.createImageSegment();
imageSegment.getTREsRawStructure().add(expltb);
new NitfCreationFlowImpl().fileHeader(() -> TreUtilityTest.createFileHeader()).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
// key value pair of nitf attributes and expected getAttributes
Map<NitfAttribute, NitfValue> assertMap = new HashMap<>();
assertMap.put(ExpltbAttribute.ANGLE_TO_NORTH_ATTRIBUTE, new NitfValue(Float.parseFloat(angleToNorth)));
assertMap.put(ExpltbAttribute.ANGLE_TO_NORTH_ACCURACY_ATTRIBUTE, new NitfValue(Float.parseFloat(angleToNorthAccuracy)));
assertMap.put(ExpltbAttribute.MODE_ATTRIBUTE, new NitfValue(mode));
assertMap.put(ExpltbAttribute.PRIME_ID_ATTRIBUTE, new NitfValue(primeId));
return assertMap;
}
Aggregations