How to use hierarchyConstructor method of org.cerberus.crud.service.impl.LabelService class

Best Cerberus-source code snippet using org.cerberus.crud.service.impl.LabelService.hierarchyConstructor

Source:LabelService.java Github

copy

Full Screen

...259 public AnswerList<String> readDistinctValuesByCriteria(String system, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {260 return labelDAO.readDistinctValuesByCriteria(system, searchParameter, individualSearch, columnName);261 }262 @Override263 public List<TreeNode> hierarchyConstructor(HashMap<Integer, TreeNode> inputList) {264 // Preparing data structure.265 // Looping against inputList to build nodeList.266 // Also saving all entry that have a parent in treeParent.267 Map<Integer, TreeNode> nodeList = new HashMap<>();268 List<TreeNode> treeParent = new ArrayList<>();269 for (Map.Entry<Integer, TreeNode> entry : inputList.entrySet()) {270 Integer key = entry.getKey();271 TreeNode localNode = entry.getValue();272 nodeList.put(localNode.getId(), localNode);273 if (localNode.getParentId() > 0) {274 treeParent.add(localNode);275 }276 }277 // Building final list278 List<TreeNode> finalList = new ArrayList<>();279 try {280 // Loop on maximum hierarchy levels.281 int i = 0;282 while (i < 50 && !nodeList.isEmpty()) {283// LOG.debug(i + ".start : " + nodeList);284 List<TreeNode> listToRemove = new ArrayList<>();285 // Looping against nodeList.286 for (Map.Entry<Integer, TreeNode> entry : nodeList.entrySet()) {287 Integer key = entry.getKey();288 TreeNode value = entry.getValue();289// LOG.debug(value.getId() + " " + value.getParentId() + " " + value.getNodes().size());290 // Does current entry has at least a child ?291 boolean hasChild = false;292 for (TreeNode treeNode : treeParent) {293 if (treeNode.getParentId() == value.getId()) {294 hasChild = true;295 }296 }297 if (!hasChild) {298 // If entry has no more child, we can add it to finalList.299 if ((i == 0) && (value.getNodes().isEmpty())) {300 value.setNodes(null);301 }302// LOG.debug("Pas de fils.");303 if (value.getParentId() <= 0) {304// LOG.debug("Adding to final result and remove from list." + i);305 if (value.getNodes() != null && !value.getNodes().isEmpty()) {306 Collections.sort(value.getNodes(), new SortbyLabel());307 }308 finalList.add(value);309 listToRemove.add(value);310 } else {311// LOG.debug("Moving to parent and remove from list." + i + " Parent " + value.getParentId());312 // Mettre sur le fils sur son pere.313 TreeNode father = nodeList.get(value.getParentId());314 if (father != null) {315 List<TreeNode> sons = father.getNodes();316 if (sons == null) {317 sons = new ArrayList<>();318 }319 if (value.getNodes() != null && !value.getNodes().isEmpty()) {320 Collections.sort(value.getNodes(), new SortbyLabel());321 }322 sons.add(value);323 father.setNodes(sons);324 father.setCounter1WithChild(father.getCounter1WithChild() + value.getCounter1WithChild());325 father.setNbNodesWithChild(father.getNbNodesWithChild() + 1);326 father.setNbOK(father.getNbOK() + value.getNbOK());327 father.setNbKO(father.getNbKO() + value.getNbKO());328 father.setNbFA(father.getNbFA() + value.getNbFA());329 father.setNbNA(father.getNbNA() + value.getNbNA());330 father.setNbNE(father.getNbNE() + value.getNbNE());331 father.setNbWE(father.getNbWE() + value.getNbWE());332 father.setNbPE(father.getNbPE() + value.getNbPE());333 father.setNbQE(father.getNbQE() + value.getNbQE());334 father.setNbQU(father.getNbQU() + value.getNbQU());335 father.setNbCA(father.getNbCA() + value.getNbCA());336 nodeList.put(father.getId(), father);337 } else {338 if (value.getNodes() != null && !value.getNodes().isEmpty()) {339// List<TreeNode> newTree = next.getNodes();340 Collections.sort(value.getNodes(), new SortbyLabel());341// next.setNodes(newTree);342 }343 // Father does not exist so we attach it to root.344 finalList.add(value);345 listToRemove.add(value);346 }347 listToRemove.add(value);348 treeParent.remove(value);349 }350 }351 }352 // Removing all entries that has been clasified to finalList.353// LOG.debug("To remove : " + listToRemove);354 for (TreeNode label : listToRemove) {355 nodeList.remove(label.getId());356 }357 i++;358 }359 // We now sort the root level (other levels were already sorted).360 Collections.sort(finalList, new SortbyLabel());361 } catch (Exception e) {362 LOG.error("Exception in hierarchyConstructor.", e);363 }364 return finalList;365 }366 class SortbyLabel implements Comparator<TreeNode> {367 // Used for sorting in ascending order of368 // Label name.369 @Override370 public int compare(TreeNode a, TreeNode b) {371 if (a != null && b != null & a.getLabel() != null) {372 return a.getLabel().compareToIgnoreCase(b.getLabel());373 } else {374 return 1;375 }376 }...

Full Screen

Full Screen

hierarchyConstructor

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.Label;2import org.cerberus.crud.service.impl.LabelService;3import java.util.List;4List<Label> labels = new LabelService().hierarchyConstructor(new LabelService().findAll());5for (Label label : labels) {6 System.out.println(label);7}

Full Screen

Full Screen

hierarchyConstructor

Using AI Code Generation

copy

Full Screen

1var labelHierarchy = new LabelHierarchy();2var labelService = new LabelService();3var label = new Label();4label.setName("Label1");5labelHierarchy = labelService.hierarchyConstructor(label);6labelHierarchy.printHierarchy();7var labelHierarchy = new LabelHierarchy();8var labelService = new LabelService();9var label = new Label();10label.setName("Label1");11labelHierarchy = labelService.hierarchyConstructor(label);12labelHierarchy.printHierarchy();13var labelHierarchy = new LabelHierarchy();14var labelService = new LabelService();15var label = new Label();16label.setName("Label1");17labelHierarchy = labelService.hierarchyConstructor(label);18labelHierarchy.printHierarchy();19var labelHierarchy = new LabelHierarchy();20var labelService = new LabelService();21var label = new Label();22label.setName("Label1");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful