use of org.apache.tools.ant.filters.StringInputStream in project Gemma by PavlidisLab.
the class ExpressionExperimentFormController method updateBioMaterialMap.
/**
* Change the relationship between bioassays and biomaterials.
*
* @param request request
* @param expressionExperiment ee
* @return true if there were changes
*/
private boolean updateBioMaterialMap(HttpServletRequest request, ExpressionExperiment expressionExperiment) {
// parse JSON-serialized map
String jsonSerialization = request.getParameter("assayToMaterialMap");
// convert back to a map
Map<String, JSONValue> bioAssayMap;
try (StringInputStream aStream = new StringInputStream(jsonSerialization)) {
JSONParser parser = new JSONParser(aStream);
bioAssayMap = ((JSONObject) parser.nextValue()).getValue();
} catch (IOException | ANTLRException e) {
throw new RuntimeException(e);
}
Map<BioAssay, BioMaterial> deleteAssociations = new HashMap<>();
Set<Entry<String, JSONValue>> bioAssays = bioAssayMap.entrySet();
boolean anyChanges = false;
int newBioMaterialCount = 0;
for (Entry<String, JSONValue> entry : bioAssays) {
// if it is, skip over this entry
if (entry.getKey().equalsIgnoreCase("nullElement")) {
continue;
}
Long bioAssayId = Long.parseLong(entry.getKey());
JSONValue value = entry.getValue();
Long newMaterialId;
if (value.isString()) {
newMaterialId = Long.parseLong(((JSONString) value).getValue());
} else {
newMaterialId = ((JSONInteger) value).getValue().longValue();
}
// maybe we need to do
BioAssay bioAssay = bioAssayService.load(bioAssayId);
if (bioAssay == null) {
throw new IllegalArgumentException("Bioassay with id=" + bioAssayId + " was not associated with the experiment");
}
BioMaterial currentBioMaterial = bioAssay.getSampleUsed();
if (newMaterialId.equals(currentBioMaterial.getId())) {
// / no change
continue;
}
BioMaterial newMaterial;
if (newMaterialId < 0) {
// This kludge signifies that it is a 'brand new' biomaterial.
newMaterial = bioMaterialService.copy(currentBioMaterial);
newMaterial.setName("Modeled after " + currentBioMaterial.getName());
newMaterial.getFactorValues().clear();
newMaterial = (BioMaterial) persisterHelper.persist(newMaterial);
newBioMaterialCount++;
} else {
// FIXME can we just use this from the experiment, probably no need to fetch it again.
newMaterial = bioMaterialService.load(newMaterialId);
if (newMaterial == null) {
throw new IllegalArgumentException("BioMaterial with id=" + newMaterialId + " could not be loaded");
}
}
anyChanges = true;
BaseFormController.log.info("Associating " + bioAssay + " with " + newMaterial);
bioAssayService.addBioMaterialAssociation(bioAssay, newMaterial);
}
if (anyChanges) {
/*
* FIXME Decide if we need to remove the biomaterial -> factor value associations, it could be completely
* fouled up.
*/
BaseFormController.log.info("There were changes to the BioMaterial -> BioAssay map");
this.audit(expressionExperiment, BioMaterialMappingUpdate.Factory.newInstance(), // remove unnecessary biomaterial associations
newBioMaterialCount + " biomaterials");
Collection<BioAssay> deleteKeys = deleteAssociations.keySet();
for (BioAssay assay : deleteKeys) {
/*
* BUG: if this fails, we end up with a useless extra biomaterial associated with the bioassay.
*/
bioAssayService.removeBioMaterialAssociation(assay, deleteAssociations.get(assay));
}
} else {
BaseFormController.log.info("There were no changes to the BioMaterial -> BioAssay map");
}
return anyChanges;
}
use of org.apache.tools.ant.filters.StringInputStream in project gora by apache.
the class StorageConfiguration method getGoraPropertiesAsProperties.
/**
* Returns the properties data in a Properties instacne
* @return
* @throws IOException
*/
public Properties getGoraPropertiesAsProperties() throws IOException {
Properties properties = new Properties();
properties.load(new StringInputStream(this.goraProperties));
if (this.getMapping() != null) {
properties.setProperty("gora.mapping", mapping);
}
return properties;
}
use of org.apache.tools.ant.filters.StringInputStream in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method roundTripUnmarshalThenMarshalUnmarshal.
public void roundTripUnmarshalThenMarshalUnmarshal(InputStream dmnXmlInputStream, Consumer<Graph<?, Node<?, ?>>> checkGraphConsumer) throws IOException {
DMNMarshallerStandalone m = getDMNMarshaller();
// first unmarshal from DMN XML to Stunner DMN Graph
@SuppressWarnings("unchecked") Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), dmnXmlInputStream);
checkGraphConsumer.accept(g);
// round trip to Stunner DMN Graph back to DMN XML
DiagramImpl diagram = createDiagram();
diagram.setGraph(g);
String mString = m.marshall(diagram);
LOG.debug(mString);
// now unmarshal once more, from the marshalled just done above, back again to Stunner DMN Graph to complete check for round-trip
@SuppressWarnings("unchecked") Graph<?, Node<?, ?>> g2 = m.unmarshall(createMetadata(), new StringInputStream(mString));
checkGraphConsumer.accept(g2);
}
use of org.apache.tools.ant.filters.StringInputStream in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method marshallAndUnMarshallConnectors.
@SuppressWarnings("unchecked")
private ViewConnector marshallAndUnMarshallConnectors(final org.kie.workbench.common.stunner.core.graph.content.Bounds bounds, final String decisionNode1UUID, final String decisionNode2UUID, final String edgeUUID, final MagnetConnection edgeSourceConnection, final MagnetConnection edgeTargetConnection, final Consumer<MagnetConnection> sourceMagnetConsumer, final Consumer<MagnetConnection> targetMagnetConsumer) throws Exception {
final DMNMarshallerStandalone marshaller = getDMNMarshaller();
final Diagram<Graph, Metadata> mockedDiagram = connectTwoNodes(bounds, decisionNode1UUID, decisionNode2UUID, edgeUUID, edgeSourceConnection, edgeTargetConnection, sourceMagnetConsumer, targetMagnetConsumer);
final String marshalledSource = marshaller.marshall(mockedDiagram);
final Graph<?, Node<View, ?>> unmarshalledGraph = marshaller.unmarshall(createMetadata(), new StringInputStream(marshalledSource));
assertNotNull(unmarshalledGraph);
final Node<?, ?> decision1Node = unmarshalledGraph.getNode(decisionNode1UUID);
final Node<?, ?> decision2Node = unmarshalledGraph.getNode(decisionNode2UUID);
assertNotNull(decision1Node);
assertNotNull(decision2Node);
assertEquals(1, decision1Node.getOutEdges().size());
assertEquals(2, decision2Node.getInEdges().size());
final Edge decision1NodeOutEdge = decision1Node.getOutEdges().get(0);
final Edge decision2NodeInEdge = decision2Node.getInEdges().get(0);
assertEquals(decision1NodeOutEdge, decision2NodeInEdge);
final ViewConnector edgeView = (ViewConnector) decision1NodeOutEdge.getContent();
assertTrue(edgeView.getSourceConnection().isPresent());
assertTrue(edgeView.getTargetConnection().isPresent());
return edgeView;
}
use of org.apache.tools.ant.filters.StringInputStream in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method roundTripUnmarshalThenMarshalUnmarshal.
public void roundTripUnmarshalThenMarshalUnmarshal(InputStream dmnXmlInputStream, Consumer<Graph<?, Node<?, ?>>> checkGraphConsumer) throws IOException {
DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
// first unmarshal from DMN XML to Stunner DMN Graph
@SuppressWarnings("unchecked") Graph<?, Node<?, ?>> g = m.unmarshall(null, dmnXmlInputStream);
checkGraphConsumer.accept(g);
// round trip to Stunner DMN Graph back to DMN XML
DiagramImpl diagram = new DiagramImpl("", null);
diagram.setGraph(g);
String mString = m.marshall(diagram);
System.out.println(mString);
// now unmarshal once more, from the marshalled just done above, back again to Stunner DMN Graph to complete check for round-trip
@SuppressWarnings("unchecked") Graph<?, Node<?, ?>> g2 = m.unmarshall(null, new StringInputStream(mString));
checkGraphConsumer.accept(g2);
}
Aggregations