| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.help.service.impl; |
| 18 | |
|
| 19 | |
import java.io.InputStream; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.List; |
| 22 | |
|
| 23 | |
import org.apache.commons.lang.StringUtils; |
| 24 | |
import org.jdom.Element; |
| 25 | |
import org.kuali.rice.core.api.impex.ExportDataSet; |
| 26 | |
import org.kuali.rice.core.framework.persistence.jta.TransactionalNoValidationExceptionRollback; |
| 27 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
| 28 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
| 29 | |
import org.kuali.rice.kew.help.HelpEntry; |
| 30 | |
import org.kuali.rice.kew.help.dao.HelpDAO; |
| 31 | |
import org.kuali.rice.kew.help.service.HelpService; |
| 32 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 33 | |
import org.kuali.rice.kew.xml.HelpEntryXmlParser; |
| 34 | |
import org.kuali.rice.kew.xml.export.HelpEntryXmlExporter; |
| 35 | |
import org.kuali.rice.krad.exception.ValidationException; |
| 36 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 37 | |
|
| 38 | |
|
| 39 | |
@TransactionalNoValidationExceptionRollback |
| 40 | 0 | public class HelpServiceImpl implements HelpService { |
| 41 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HelpServiceImpl.class); |
| 42 | |
private HelpDAO helpDAO; |
| 43 | |
|
| 44 | |
private static final String HELP_NAME_KEY = "helpEntry.helpName"; |
| 45 | |
private static final String HELP_KEY_KEY = "helpEntry.helpKey"; |
| 46 | |
private static final String HELP_TEXT_KEY = "helpEntry.helpText"; |
| 47 | |
private static final String HELP_ID_KEY = "helpEntry.helpId"; |
| 48 | |
private static final String ID_INVALID = "helpentry.id.invalid"; |
| 49 | |
private static final String NAME_EMPTY = "helpentry.name.empty"; |
| 50 | |
private static final String TEXT_EMPTY = "helpentry.text.empty"; |
| 51 | |
private static final String KEY_EMPTY = "helpentry.key.empty"; |
| 52 | |
private static final String KEY_EXIST = "helpentry.key.exists"; |
| 53 | |
private static final String KEY_ILLEGAL = "helpentry.key.illegal"; |
| 54 | |
|
| 55 | |
public void save(HelpEntry helpEntry){ |
| 56 | 0 | validateHelpEntry(helpEntry); |
| 57 | 0 | getHelpDAO().save(helpEntry); |
| 58 | 0 | } |
| 59 | |
|
| 60 | |
public void saveXmlEntry(HelpEntry helpEntry){ |
| 61 | 0 | HelpEntry entry=validateXmlHelpEntry(helpEntry); |
| 62 | 0 | LOG.debug(entry.getHelpId()+", "+entry.getHelpName()+", "+entry.getHelpText()+", "+entry.getHelpKey()); |
| 63 | 0 | getHelpDAO().save(entry); |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
public void delete(HelpEntry helpEntry){ |
| 67 | 0 | getHelpDAO().deleteEntry(helpEntry); |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
private HelpEntry validateXmlHelpEntry(HelpEntry helpEntry){ |
| 71 | 0 | LOG.debug("Enter validateXMLHelpEntry(..)"); |
| 72 | |
|
| 73 | 0 | if (helpEntry.getHelpName() == null || "".equals(helpEntry.getHelpName().trim())) { |
| 74 | 0 | GlobalVariables.getMessageMap().putError(HELP_NAME_KEY, NAME_EMPTY); |
| 75 | |
} |
| 76 | 0 | if (helpEntry.getHelpText() == null || "".equals(helpEntry.getHelpText().trim())) { |
| 77 | 0 | GlobalVariables.getMessageMap().putError(HELP_TEXT_KEY, TEXT_EMPTY); |
| 78 | |
} else { |
| 79 | 0 | helpEntry.setHelpText(helpEntry.getHelpText().trim()); |
| 80 | |
} |
| 81 | |
|
| 82 | 0 | if (helpEntry.getHelpKey() == null || "".equals(helpEntry.getHelpKey().trim())) { |
| 83 | 0 | GlobalVariables.getMessageMap().putError(HELP_KEY_KEY, KEY_EMPTY); |
| 84 | 0 | } else if (helpEntry.getHelpKey().contains("'")) { |
| 85 | 0 | GlobalVariables.getMessageMap().putError(HELP_KEY_KEY, KEY_ILLEGAL, "'"); |
| 86 | |
} else { |
| 87 | 0 | helpEntry.setHelpKey(helpEntry.getHelpKey().trim()); |
| 88 | 0 | HelpEntry entry1=findByKey(helpEntry.getHelpKey()); |
| 89 | 0 | if(helpEntry.getHelpId() == null && entry1 != null){ |
| 90 | 0 | String id=entry1.getHelpId(); |
| 91 | |
|
| 92 | 0 | helpEntry.setHelpId(id); |
| 93 | 0 | helpEntry.setLockVerNbr(entry1.getLockVerNbr()); |
| 94 | |
|
| 95 | |
} |
| 96 | |
} |
| 97 | |
|
| 98 | 0 | LOG.debug("Exit validateXmlHelpEntry(..)"); |
| 99 | 0 | if (GlobalVariables.getMessageMap().hasErrors()) { |
| 100 | 0 | throw new ValidationException("errors in help"); |
| 101 | |
} |
| 102 | 0 | return helpEntry; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
private void validateHelpEntry(HelpEntry helpEntry){ |
| 107 | 0 | LOG.debug("Enter validateHelpEntry(..)"); |
| 108 | 0 | List errors = new ArrayList(); |
| 109 | |
|
| 110 | 0 | if (helpEntry.getHelpName() == null || "".equals(helpEntry.getHelpName().trim())) { |
| 111 | 0 | GlobalVariables.getMessageMap().putError(HELP_NAME_KEY, NAME_EMPTY); |
| 112 | |
} |
| 113 | 0 | if (helpEntry.getHelpText() == null || "".equals(helpEntry.getHelpText().trim())) { |
| 114 | 0 | GlobalVariables.getMessageMap().putError(HELP_TEXT_KEY, TEXT_EMPTY); |
| 115 | |
} else { |
| 116 | 0 | helpEntry.setHelpText(helpEntry.getHelpText().trim()); |
| 117 | |
} |
| 118 | |
|
| 119 | 0 | if (helpEntry.getHelpKey() == null || "".equals(helpEntry.getHelpKey().trim())) { |
| 120 | 0 | GlobalVariables.getMessageMap().putError(HELP_KEY_KEY, KEY_EMPTY); |
| 121 | 0 | } else if (helpEntry.getHelpKey().contains("'")){ |
| 122 | 0 | GlobalVariables.getMessageMap().putError(HELP_KEY_KEY, KEY_ILLEGAL, "'"); |
| 123 | |
} else { |
| 124 | 0 | helpEntry.setHelpKey(helpEntry.getHelpKey().trim()); |
| 125 | 0 | if(helpEntry.getHelpId() == null && findByKey(helpEntry.getHelpKey()) != null){ |
| 126 | 0 | GlobalVariables.getMessageMap().putError(HELP_KEY_KEY, KEY_EXIST, helpEntry.getHelpKey()); |
| 127 | |
} |
| 128 | |
} |
| 129 | |
|
| 130 | 0 | LOG.debug("Exit validateHelpEntry(..)"); |
| 131 | 0 | if (GlobalVariables.getMessageMap().hasErrors()) { |
| 132 | 0 | throw new ValidationException("errors in help"); |
| 133 | |
} |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
public HelpEntry findByKey(String helpKey){ |
| 137 | 0 | return getHelpDAO().findByKey(helpKey); |
| 138 | |
} |
| 139 | |
|
| 140 | |
public HelpDAO getHelpDAO() { |
| 141 | 0 | return helpDAO; |
| 142 | |
} |
| 143 | |
public void setHelpDAO(HelpDAO helpDAO) { |
| 144 | 0 | this.helpDAO = helpDAO; |
| 145 | 0 | } |
| 146 | |
|
| 147 | |
public HelpEntry findById(String helpId){ |
| 148 | 0 | return getHelpDAO().findById(helpId); |
| 149 | |
} |
| 150 | |
|
| 151 | |
public List search(HelpEntry helpEntry){ |
| 152 | 0 | if(helpEntry.getHelpId() != null && StringUtils.equals(helpEntry.getHelpId(), "0")){ |
| 153 | 0 | GlobalVariables.getMessageMap().putError(HELP_ID_KEY, ID_INVALID); |
| 154 | |
} |
| 155 | 0 | if (GlobalVariables.getMessageMap().hasErrors()) { |
| 156 | 0 | throw new ValidationException("errors in help"); |
| 157 | |
} |
| 158 | |
|
| 159 | 0 | return getHelpDAO().search(helpEntry); |
| 160 | |
} |
| 161 | |
|
| 162 | |
public void loadXml(InputStream inputStream, String principalId){ |
| 163 | 0 | HelpEntryXmlParser parser = new HelpEntryXmlParser(); |
| 164 | |
try { |
| 165 | 0 | parser.parseHelpEntries(inputStream); |
| 166 | 0 | } catch(Exception e){ |
| 167 | 0 | throw new WorkflowServiceErrorException("Error parsing help XML file", new WorkflowServiceErrorImpl("Error parsing xml file.", KEWConstants.XML_FILE_PARSE_ERROR) ); |
| 168 | 0 | } |
| 169 | 0 | } |
| 170 | |
|
| 171 | |
public Element export(ExportDataSet dataSet) { |
| 172 | 0 | HelpEntryXmlExporter exporter = new HelpEntryXmlExporter(); |
| 173 | 0 | return exporter.export(dataSet); |
| 174 | |
} |
| 175 | |
|
| 176 | |
@Override |
| 177 | |
public boolean supportPrettyPrint() { |
| 178 | 0 | return true; |
| 179 | |
} |
| 180 | |
|
| 181 | |
} |