View Javadoc
1   package org.kuali.rice.krms.impl.repository;
2   
3   import org.kuali.rice.core.api.criteria.QueryByCriteria;
4   import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
5   import org.kuali.rice.krad.data.DataObjectService;
6   import org.kuali.rice.krad.data.PersistenceOption;
7   import org.kuali.rice.krms.api.repository.term.TermDefinition;
8   import org.kuali.rice.krms.impl.util.KrmsImplConstants;
9   
10  /**
11   * This class is a temp fix to resolve the issue https://jira.kuali.org/browse/KSENROLL-12746
12   * It was coded to use the constant TERM_ID("termId") instead of "term.id"
13   */
14  public class TempFixTermBoServiceImpl extends TermBoServiceImpl {
15  
16      protected DataObjectService dataObjectService;
17  
18      @Override
19      public void setDataObjectService(DataObjectService dataObjectService) {
20          this.dataObjectService = dataObjectService;
21          super.setDataObjectService(dataObjectService);
22      }
23  
24      @Override
25      public void updateTerm(TermDefinition term) throws RiceIllegalArgumentException {
26          if (term == null) {
27              throw new IllegalArgumentException("term is null");
28          }
29  
30          // must already exist to be able to update
31          final String termId = term.getId();
32          final TermBo existing = dataObjectService.find(TermBo.class, termId);
33  
34          if (existing == null) {
35              throw new IllegalStateException("the term resolver does not exist: " + term);
36          }
37  
38          final TermDefinition toUpdate;
39  
40          if (!existing.getId().equals(term.getId())) {
41              // if passed in id does not match existing id, correct it
42              final TermDefinition.Builder builder = TermDefinition.Builder.create(term);
43              builder.setId(existing.getId());
44              toUpdate = builder.build();
45          } else {
46              toUpdate = term;
47          }
48  
49          // copy all updateable fields to bo
50          TermBo boToUpdate = TermBo.from(toUpdate);
51  
52          // delete any old, existing parameters
53  
54  //        QueryByCriteria crit =
55  //                QueryByCriteria.Builder.forAttribute("term.id", toUpdate.getId()).build();
56  //        dataObjectService.deleteMatching(TermParameterBo.class, crit);
57  
58          // update the rule and create new attributes
59          dataObjectService.save(boToUpdate, PersistenceOption.FLUSH);
60      }
61  }