@Test(expectedExceptions = RuntimeException.class) public void should_not_find_ordinal() { Ordinals ordinals = new Ordinals(mock(ArchetypeManager.class)); ordinals.getOrdinalVO(null, TEST_ARCHETYPE_ID + "/archetypeElementPath1", "testCode1"); }
public OrdinalVO getOrdinalVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!ordinalByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getOrdinals(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getTemplateOrdinals(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' with template '%s'", elementId, templateId)); } return getTemplateOrdinals(templateId).get(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } }
Ordinals { public OrdinalVO getOrdinalVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!ordinalByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getOrdinals(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getTemplateOrdinals(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' with template '%s'", elementId, templateId)); } return getTemplateOrdinals(templateId).get(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } } }
Ordinals { public OrdinalVO getOrdinalVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!ordinalByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getOrdinals(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getTemplateOrdinals(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' with template '%s'", elementId, templateId)); } return getTemplateOrdinals(templateId).get(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } } Ordinals(ArchetypeManager archetypeManager); }
Ordinals { public OrdinalVO getOrdinalVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!ordinalByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getOrdinals(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getTemplateOrdinals(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' with template '%s'", elementId, templateId)); } return getTemplateOrdinals(templateId).get(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } } Ordinals(ArchetypeManager archetypeManager); void init(); OrdinalVO getOrdinalVO(String templateId, String elementId, String code); List<OrdinalVO> getOrdinalVOs(String idTemplate, String elementId); String getText(OrdinalVO ordinalVO, String lang); String getText(String idTemplate, String idElement, String ordinalKey, String lang); String getDescription(OrdinalVO ordinalVO, String lang); String getDescription(String idTemplate, String idElement, String ordinalKey, String lang); }
Ordinals { public OrdinalVO getOrdinalVO(String templateId, String elementId, String code) { archetypeManager.loadArchetypesAndTemplatesIfNeeded(templateId, elementId); if (templateId == null) { if (!ordinalByElementId.containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s'", elementId)); } return getOrdinals(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s'", code, elementId))); } else { if (!getTemplateOrdinals(templateId).containsKey(elementId)) { throw new RuntimeException(format("Could not find element '%s' with template '%s'", elementId, templateId)); } return getTemplateOrdinals(templateId).get(elementId) .stream() .filter(o -> o.getCode().equals(code)) .findFirst() .orElseThrow(() -> new RuntimeException(format("Could not find code '%s' in element '%s' with template '%s'", code, elementId, templateId))); } } Ordinals(ArchetypeManager archetypeManager); void init(); OrdinalVO getOrdinalVO(String templateId, String elementId, String code); List<OrdinalVO> getOrdinalVOs(String idTemplate, String elementId); String getText(OrdinalVO ordinalVO, String lang); String getText(String idTemplate, String idElement, String ordinalKey, String lang); String getDescription(OrdinalVO ordinalVO, String lang); String getDescription(String idTemplate, String idElement, String ordinalKey, String lang);  }