BrightSide Workbench Full Report + Source Code
GroupItUtil.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.groupit;
20 
21 import java.util.Collection;
22 import org.turro.string.Strings;
23 import org.turro.contacts.FieldIt;
24 import org.turro.contacts.Grouped;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.fieldit.FieldItSet;
28 import org.turro.fieldit.FieldItUtil;
29 import org.turro.fieldit.ValueItSet;
30 import org.turro.jpa.Dao;
31 
36 public class GroupItUtil {
37 
38  public static void saveValues(Collection<Grouped> values) {
39  Dao dao = new ContactsPU();
40  for(Grouped v : values) {
41  if(v.isValid()) {
42  dao.saveObject(v);
43  } else if(!Strings.isBlank(v.getId())) {
44  dao.deleteObject(v);
45  }
46  }
47  }
48 
49  public static void setSelectedGroup(IConstructor constructor, String pathOrigin, String value) {
50  if(value != null) {
51  constructor.setSessionAttribute(pathOrigin + "-selected-group", value);
52  }
53  }
54 
55  public static String getSelectedGroup(IConstructor constructor, String pathOrigin) {
56  return (String) constructor.getSessionAttribute(pathOrigin + "-selected-group");
57  }
58 
59  public static void setCategory(IConstructor constructor, String pathOrigin, String value) {
60  if(value != null) {
61  constructor.setSessionAttribute(pathOrigin + "-selected-category", value);
62  }
63  }
64 
65  public static String getCategory(IConstructor constructor, String pathOrigin) {
66  return (String) constructor.getSessionAttribute(pathOrigin + "-selected-category");
67  }
68 
69  public static Collection<String> getPathsFromGroup(String path, String selectedGroup, String selectedCategory) {
70  return getPathsFromGroup(path, selectedGroup, selectedCategory, false);
71  }
72 
73  public static Collection<String> getPathsFromGroup(String path, String selectedGroup, String selectedCategory, boolean exact) {
74  return Grouped.paths(path, selectedGroup, selectedCategory, exact);
75  }
76 
77  public static Collection<String> getPathsFromCategory(String path, String category) {
78  return Grouped.pathsFromCategory(path, category);
79  }
80 
81  public static FieldItSet getFields(String entityPath) {
82  Collection<Grouped> groups = Grouped.groups(entityPath);
83  FieldItSet fis = new FieldItSet();
84  for(Grouped g : groups) {
85  fis.addAll(g.getParent().fields());
86  }
87  return fis;
88  }
89 
90  public static ValueItSet getValues(String entityPath) {
91  ValueItSet vis = new ValueItSet();
92  for(FieldIt fi : getFields(entityPath)) {
93  vis.add(FieldItUtil.value(fi, entityPath));
94  }
95  return vis;
96  }
97 
98  private GroupItUtil() {
99  }
100 
101 }
static Collection< String > paths(String path, String selectedGroup, String selectedCategory, boolean exact)
Definition: Grouped.java:135
static Collection< Grouped > groups(Object entity, String category)
Definition: Grouped.java:98
static Collection< String > pathsFromCategory(String path, String category)
Definition: Grouped.java:157
static ValueIt value(FieldIt field, String path)
static String getCategory(IConstructor constructor, String pathOrigin)
static void setSelectedGroup(IConstructor constructor, String pathOrigin, String value)
static ValueItSet getValues(String entityPath)
static void setCategory(IConstructor constructor, String pathOrigin, String value)
static Collection< String > getPathsFromCategory(String path, String category)
static FieldItSet getFields(String entityPath)
static void saveValues(Collection< Grouped > values)
static Collection< String > getPathsFromGroup(String path, String selectedGroup, String selectedCategory)
static Collection< String > getPathsFromGroup(String path, String selectedGroup, String selectedCategory, boolean exact)
static String getSelectedGroup(IConstructor constructor, String pathOrigin)
void deleteObject(Object obj)
Definition: Dao.java:162
void setSessionAttribute(String key, Object value)