public void setId(String value) { // ids should be properly sanitized at a higher level String sanitized = Objects.nonNull(value) ? value.replaceAll("\\s", "") : value; process.setId(sanitized); }
public void updateIDs(Definitions def) { // data object id update List<RootElement> rootElements = def.getRootElements(); for (RootElement root : rootElements) { if (root instanceof Process) { Process process = (Process) root; if (process.getId() != null) { String processId = process.getId().trim(); processId = processId.replaceAll("\\s", ""); process.setId(processId); } List<FlowElement> flowElements = process.getFlowElements(); for (FlowElement fe : flowElements) { if (fe instanceof DataObject) { DataObject da = (DataObject) fe; if (da.getName() != null) { String daId = da.getName().trim(); daId = daId.replaceAll("\\W", ""); da.setId(daId); } } } } } }
wrapInCDATABlock(properties.get("customdescription"))); rootLevelProcess.setId(properties.get("id")); applyProcessProperties(rootLevelProcess, properties); wrapInCDATABlock(properties.get("customdescription"))); rootLevelProcess.setId(properties.get("id")); applyProcessProperties(rootLevelProcess, properties);
@Test public void testUpdateIDs() { Definitions defs = mock(Definitions.class); Process process = mock(Process.class); DataObject flowElement = mock(DataObject.class); final Value<String> processId = new Value<>("Project:Bad Id"); final Value<String> flowElementId = new Value<>("Bad Flow Id!"); when(process.getId()).thenAnswer((m) -> processId.get()); doAnswer((m) -> { processId.set(m.getArgumentAt(0, String.class)); return null; }).when(process).setId(anyString()); when(flowElement.getId()).thenAnswer((m) -> flowElementId.get()); when(flowElement.getName()).thenAnswer((m) -> flowElementId.get()); doAnswer((m) -> { flowElementId.set(m.getArgumentAt(0, String.class)); return null; }).when(flowElement).setId(anyString()); when(process.getFlowElements()).thenReturn(Arrays.asList(flowElement)); when(defs.getRootElements()).thenReturn(Arrays.asList(process)); tested.updateIDs(defs); assertEquals("Project:BadId", processId.get()); assertEquals("BadFlowId", flowElementId.get()); }