01: package com.technoetic.xplanner.actions;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.http.HttpServletResponse;
05:
06: import org.apache.commons.lang.StringUtils;
07: import org.apache.struts.action.ActionForm;
08: import org.apache.struts.action.ActionForward;
09: import org.apache.struts.action.ActionMapping;
10:
11: import com.technoetic.xplanner.db.IdSearchHelper;
12: import com.technoetic.xplanner.domain.DomainMetaDataRepository;
13: import com.technoetic.xplanner.domain.DomainObject;
14: import com.technoetic.xplanner.forms.AbstractEditorForm;
15:
16: public class IdSearchAction extends AbstractAction {
17: public IdSearchHelper idSearchHelper = new IdSearchHelper();
18: private DomainMetaDataRepository metaDataRepository;
19:
20: protected ActionForward doExecute(ActionMapping mapping,
21: ActionForm form, HttpServletRequest request,
22: HttpServletResponse response) throws Exception {
23: AbstractEditorForm.initConverters(request); // DEBT(SPRING) Extract the convert methods out of the AbstractEditorForm (keep delegators methods) and have that object spring loaded using the message bundle from spring
24: String searchedIdString = request.getParameter("searchedId");
25: if (StringUtils.isEmpty(searchedIdString))
26: return getGeneralErrorForward(mapping, request,
27: "idsearch.error.missingId");
28:
29: Number integer = AbstractEditorForm
30: .convertToInt(searchedIdString);
31: if (integer == null)
32: return getGeneralErrorForward(mapping, request,
33: "idsearch.error.badId", searchedIdString);
34:
35: int oid = integer.intValue();
36: DomainObject object = idSearchHelper.search(oid);
37: if (object == null)
38: return getGeneralErrorForward(mapping, request,
39: "idsearch.error.idNotFound", new Integer(oid));
40:
41: //DEBT(SPRING): DomainMetaDataRep should be made an instance and spring injected
42: String objectType = metaDataRepository.classToTypeName(object
43: .getClass());
44: return new ActionForward("/do/view/" + objectType + "?oid="
45: + object.getId(), true);
46: }
47:
48: public void setMetaDataRepository(
49: DomainMetaDataRepository metaDataRepository) {
50: this.metaDataRepository = metaDataRepository;
51: }
52: }
|