TreeNodeCodeGenerator extends AbstractValueGenerator<IdmTreeNodeDto> { @Override public IdmTreeNodeDto generate(IdmTreeNodeDto dto, IdmGenerateValueDto valueGenerator) { Assert.notNull(dto, "DTO is required."); Assert.notNull(valueGenerator, "Value generator is required."); String code = dto.getName(); if (code == null) { return dto; } if (!valueGenerator.isRegenerateValue() && StringUtils.isNotEmpty(dto.getCode())) { return dto; } code = StringUtils.stripAccents(code); code = StringUtils.deleteWhitespace(code); code = code.toLowerCase(); dto.setCode(code); return dto; }  @Override String getName(); @Override IdmTreeNodeDto generate(IdmTreeNodeDto dto, IdmGenerateValueDto valueGenerator); static final String GENERATOR_NAME; }
@Test public void testWhiteSpace() { IdmTreeTypeDto type = getHelper().createTreeType(); IdmTreeNodeDto node = new IdmTreeNodeDto(); node.setTreeType(type.getId()); node.setName(" no de- test123"); IdmGenerateValueDto generator = this.createGenerator(getDtoType(), getGeneratorType(), null, 1, null); IdmTreeNodeDto generated = valueGeneratorManager.generate(node); assertNotNull(generated.getCode()); assertEquals("node-test123", generated.getCode()); generatedAttributeService.delete(generator); }
@Test public void testDiacritics() { IdmTreeTypeDto type = getHelper().createTreeType(); IdmTreeNodeDto node = new IdmTreeNodeDto(); node.setTreeType(type.getId()); node.setName("abcdřřřžžžééé"); IdmGenerateValueDto generator = this.createGenerator(getDtoType(), getGeneratorType(), null, 1, null); IdmTreeNodeDto generated = valueGeneratorManager.generate(node); assertNotNull(generated.getCode()); assertEquals("abcdrrrzzzeee", generated.getCode()); generatedAttributeService.delete(generator); }
@Test public void testAllCombination() { IdmTreeTypeDto type = getHelper().createTreeType(); IdmTreeNodeDto node = new IdmTreeNodeDto(); node.setTreeType(type.getId()); node.setName("ABCDa bc dř Ř ř"); IdmGenerateValueDto generator = this.createGenerator(getDtoType(), getGeneratorType(), null, 1, null); IdmTreeNodeDto generated = valueGeneratorManager.generate(node); assertNotNull(generated.getCode()); assertEquals("abcdabcdrrr", generated.getCode()); generatedAttributeService.delete(generator); }
@Test public void testNullName() { IdmTreeTypeDto type = getHelper().createTreeType(); IdmTreeNodeDto node = new IdmTreeNodeDto(); node.setTreeType(type.getId()); node.setName(null); IdmGenerateValueDto generator = this.createGenerator(getDtoType(), getGeneratorType(), null, 1, null); IdmTreeNodeDto generated = valueGeneratorManager.generate(node); assertNull(generated.getCode()); generatedAttributeService.delete(generator); }
@Test public void testEmptyName() { IdmTreeTypeDto type = getHelper().createTreeType(); IdmTreeNodeDto node = new IdmTreeNodeDto(); node.setTreeType(type.getId()); node.setName(""); IdmGenerateValueDto generator = this.createGenerator(getDtoType(), getGeneratorType(), null, 1, null); IdmTreeNodeDto generated = valueGeneratorManager.generate(node); assertNotNull(generated.getCode()); assertTrue(generated.getCode().isEmpty()); generatedAttributeService.delete(generator); }