@Test(expectedExceptions = RuntimeException.class) public void should_not_find_coded_text() { CodedTexts codedTexts = new CodedTexts(mock(ArchetypeManager.class)); codedTexts.getCodedTextVO(null, TEST_ARCHETYPE_ID + "/archetypeElementPath1", "testCode1"); }
public CodedTextVO getCodedTextVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!codedTextByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getCodedTexts(elementId) .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getCodedTextTemplateMap(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' in template '%s'", elementId, templateId)); } List<CodedTextVO> codedTextVOS = getCodedTextTemplateMap(templateId).get(elementId); if (codedTextVOS.isEmpty()) { throw new RuntimeException(format("Could not find coded texts for element '%s' in template '%s'", elementId, templateId)); } CodedTextVO firstCodedText = codedTextVOS.iterator().next(); if (isLocalTerminology(firstCodedText)) { return codedTextVOS .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } else { return null; } } }
CodedTexts { public CodedTextVO getCodedTextVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!codedTextByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getCodedTexts(elementId) .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getCodedTextTemplateMap(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' in template '%s'", elementId, templateId)); } List<CodedTextVO> codedTextVOS = getCodedTextTemplateMap(templateId).get(elementId); if (codedTextVOS.isEmpty()) { throw new RuntimeException(format("Could not find coded texts for element '%s' in template '%s'", elementId, templateId)); } CodedTextVO firstCodedText = codedTextVOS.iterator().next(); if (isLocalTerminology(firstCodedText)) { return codedTextVOS .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } else { return null; } } } }
CodedTexts { public CodedTextVO getCodedTextVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!codedTextByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getCodedTexts(elementId) .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getCodedTextTemplateMap(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' in template '%s'", elementId, templateId)); } List<CodedTextVO> codedTextVOS = getCodedTextTemplateMap(templateId).get(elementId); if (codedTextVOS.isEmpty()) { throw new RuntimeException(format("Could not find coded texts for element '%s' in template '%s'", elementId, templateId)); } CodedTextVO firstCodedText = codedTextVOS.iterator().next(); if (isLocalTerminology(firstCodedText)) { return codedTextVOS .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } else { return null; } } } CodedTexts(ArchetypeManager archetypeManager); }
CodedTexts { public CodedTextVO getCodedTextVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!codedTextByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getCodedTexts(elementId) .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getCodedTextTemplateMap(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' in template '%s'", elementId, templateId)); } List<CodedTextVO> codedTextVOS = getCodedTextTemplateMap(templateId).get(elementId); if (codedTextVOS.isEmpty()) { throw new RuntimeException(format("Could not find coded texts for element '%s' in template '%s'", elementId, templateId)); } CodedTextVO firstCodedText = codedTextVOS.iterator().next(); if (isLocalTerminology(firstCodedText)) { return codedTextVOS .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } else { return null; } } } CodedTexts(ArchetypeManager archetypeManager); void init(); CodedTextVO getCodedTextVO(String templateId, String elementId, String code); List<CodedTextVO> getCodedTextVOs(String idTemplate, String elementId); String getText(CodedTextVO codedTextVO, String lang); String getText(String idTemplate, String idElement, String code, String lang); String getDescription(CodedTextVO codedTextVO, String lang); String getDescription(String idTemplate, String idElement, String code, String lang); }
CodedTexts { public CodedTextVO getCodedTextVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!codedTextByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getCodedTexts(elementId) .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getCodedTextTemplateMap(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' in template '%s'", elementId, templateId)); } List<CodedTextVO> codedTextVOS = getCodedTextTemplateMap(templateId).get(elementId); if (codedTextVOS.isEmpty()) { throw new RuntimeException(format("Could not find coded texts for element '%s' in template '%s'", elementId, templateId)); } CodedTextVO firstCodedText = codedTextVOS.iterator().next(); if (isLocalTerminology(firstCodedText)) { return codedTextVOS .stream() .filter(c -> c.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } else { return null; } } } CodedTexts(ArchetypeManager archetypeManager); void init(); CodedTextVO getCodedTextVO(String templateId, String elementId, String code); List<CodedTextVO> getCodedTextVOs(String idTemplate, String elementId); String getText(CodedTextVO codedTextVO, String lang); String getText(String idTemplate, String idElement, String code, String lang); String getDescription(CodedTextVO codedTextVO, String lang); String getDescription(String idTemplate, String idElement, String code, String lang);  }