use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document in project nhin-d by DirectProject.
the class DirectDocuments method toProvideAndRegisterDocumentSetRequestType.
public ProvideAndRegisterDocumentSetRequestType toProvideAndRegisterDocumentSetRequestType() throws IOException {
ProvideAndRegisterDocumentSetRequestType request = new ProvideAndRegisterDocumentSetRequestType();
request.setSubmitObjectsRequest(this.getSubmitObjectsRequest());
for (DirectDocument2 document : documents) {
if (document.getData() != null) {
DataSource source = new ByteArrayDataSource(document.getData(), document.getMetadata().getMimeType());
DataHandler dhnew = new DataHandler(source);
Document pdoc = new Document();
pdoc.setValue(dhnew);
String id = document.getMetadata().getId();
pdoc.setId(id);
request.getDocument().add(pdoc);
}
}
return request;
}
use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document in project nhin-d by DirectProject.
the class DefaultXdmXdsTransformer method transform.
/*
* (non-Javadoc)
*
* @see org.nhindirect.transform.XdmXdsTransformer#transform(java.io.File)
*/
@Override
public ProvideAndRegisterDocumentSetRequestType transform(File file) throws TransformationException {
LOGGER.trace("Begin transformation of XDM to XDS (file)");
String docId = null;
ZipFile zipFile = null;
String docName = getDocName(file);
if (docName != null) {
XDM_FILENAME_DATA = docName;
}
ProvideAndRegisterDocumentSetRequestType prsr = new ProvideAndRegisterDocumentSetRequestType();
try {
zipFile = new ZipFile(file, ZipFile.OPEN_READ);
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
ZipEntry zipEntry = null;
// load the ZIP archive into memory
while (zipEntries.hasMoreElements()) {
zipEntry = zipEntries.nextElement();
String zname = zipEntry.getName();
LOGGER.trace("Processing a ZipEntry " + zname);
if (!zipEntry.isDirectory()) {
String subsetDirspec = getSubmissionSetDirspec(zipEntry.getName());
// Read metadata
if (matchName(zname, subsetDirspec, XDM_FILENAME_METADATA)) {
ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
SubmitObjectsRequest submitObjectRequest = (SubmitObjectsRequest) XmlUtils.unmarshal(byteArrayOutputStream.toString(), oasis.names.tc.ebxml_regrep.xsd.lcm._3.ObjectFactory.class);
prsr.setSubmitObjectsRequest(submitObjectRequest);
docId = getDocId(submitObjectRequest);
} else // Read data
if (matchName(zname, subsetDirspec, XDM_FILENAME_DATA)) {
ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
DataSource source = new ByteArrayDataSource(byteArrayOutputStream.toByteArray(), MimeType.APPLICATION_XML + "; charset=UTF-8");
DataHandler dhnew = new DataHandler(source);
Document pdoc = new Document();
pdoc.setValue(dhnew);
pdoc.setId(docId);
List<Document> docs = prsr.getDocument();
docs.add(pdoc);
}
}
if (!prsr.getDocument().isEmpty()) {
((Document) prsr.getDocument().get(0)).setId(zname);
}
}
zipFile.close();
} catch (Exception e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unable to complete transformation.", e);
}
throw new TransformationException("Unable to complete transformation.", e);
}
return prsr;
}
use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document in project nhin-d by DirectProject.
the class DefaultXdsDirectDocumentsTransformer method transform.
@Override
public DirectDocuments transform(ProvideAndRegisterDocumentSetRequestType provideAndRegisterDocumentSetRequestType) throws TransformationException {
DirectDocuments documents = new DirectDocuments();
try {
documents.setValues(provideAndRegisterDocumentSetRequestType.getSubmitObjectsRequest());
} catch (MetadataException e) {
throw new TransformationException("Unable to complete transformation due to metadata error", e);
}
for (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document document : provideAndRegisterDocumentSetRequestType.getDocument()) {
byte[] data = null;
try {
DataHandler dataHandler = document.getValue();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
dataHandler.writeTo(outputStream);
data = outputStream.toByteArray();
} catch (IOException e) {
throw new TransformationException("Unable to complete transformation due to document IO error", e);
}
DirectDocument2 doc = documents.getDocumentByUniqueId(document.getId());
if (doc != null) {
doc.setData(data);
} else {
documents.getDocumentById(document.getId()).setData(data);
}
}
return documents;
}
use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document in project hale by halestudio.
the class TestModelRifToRifTranslator method testTranslateExample3CPComplexFilter.
/**
* Tests that it is possible to translate the example 3 CP source dataset,
* including a slightly more complex predicate filter.
*
* @throws TranslationException
* if any errors occurred during the translation
* @throws JAXBException
* if unable to write out a DOM document containing the RIF-PRD
*/
@Test
public void testTranslateExample3CPComplexFilter() throws TranslationException, JAXBException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_complex_logical_filter.goml");
org.w3._2007.rif.Document doc = translator.translate(url);
assertNotNull(doc);
assertNotNull(doc.getPayload());
assertNotNull(doc.getPayload().getGroup());
assertNotNull(doc.getPayload().getGroup().getSentence());
assertThat(doc.getPayload().getGroup().getSentence().size(), is(1));
assertNotNull(doc.getPayload().getGroup().getSentence().get(0));
checkJavaBindings(doc);
writeDom(getDomFromRif(doc), System.out);
}
use of ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document in project hale by halestudio.
the class TestModelRifToRifTranslator method testTranslateExample3CPSimpleFilter.
/**
* Tests that it is possible to translate the example 3 CP source dataset,
* including a simple predicate filter.
*
* @throws TranslationException
* if any errors occurred during the translation
* @throws JAXBException
* if unable to write out a DOM document containing the RIF-PRD
*/
@Test
public void testTranslateExample3CPSimpleFilter() throws TranslationException, JAXBException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp_filter.goml");
org.w3._2007.rif.Document doc = translator.translate(url);
assertNotNull(doc);
assertNotNull(doc.getPayload());
assertNotNull(doc.getPayload().getGroup());
assertNotNull(doc.getPayload().getGroup().getSentence());
assertThat(doc.getPayload().getGroup().getSentence().size(), is(1));
assertNotNull(doc.getPayload().getGroup().getSentence().get(0));
checkJavaBindings(doc);
writeDom(getDomFromRif(doc), System.out);
}
Aggregations