📄 localpublishersessionbean.java
字号:
/** * Adds a publisher to the database. * * @throws PublisherExistsException if hard token already exists. * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public void addPublisher(Admin admin, String name, BasePublisher publisher) throws PublisherExistsException { debug(">addPublisher(name: " + name + ")"); addPublisher(admin,findFreePublisherId().intValue(),name,publisher); debug("<addPublisher()"); } // addPublisher /** * Adds a publisher to the database. * Used for importing and exporting profiles from xml-files. * * @throws PublisherExistsException if hard token already exists. * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public void addPublisher(Admin admin, int id, String name, BasePublisher publisher) throws PublisherExistsException { debug(">addPublisher(name: " + name + ", id: " + id + ")"); boolean success = false; try { publisherhome.findByName(name); } catch (FinderException e) { try { publisherhome.findByPrimaryKey(new Integer(id)); } catch (FinderException f) { try { publisherhome.create(new Integer(id), name, publisher); success = true; } catch (CreateException g) { String msg = intres.getLocalizedMessage("publisher.erroraddpublisher", name); error(msg, g); } } } if (success) { String msg = intres.getLocalizedMessage("publisher.addedpublisher", name); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, msg); } else { String msg = intres.getLocalizedMessage("publisher.erroraddpublisher", name); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, msg); } if (!success) throw new PublisherExistsException(); debug("<addPublisher()"); } // addPublisher /** * Updates publisher data * * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public void changePublisher(Admin admin, String name, BasePublisher publisher) { debug(">changePublisher(name: " + name + ")"); boolean success = false; try { PublisherDataLocal htp = publisherhome.findByName(name); htp.setPublisher(publisher); success = true; } catch (FinderException e) { } if (success) { String msg = intres.getLocalizedMessage("publisher.changedpublisher", name); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, msg); } else { String msg = intres.getLocalizedMessage("publisher.errorchangepublisher", name); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, msg); } debug("<changePublisher()"); } // changePublisher /** * Adds a publisher with the same content as the original. * * @throws PublisherExistsException if publisher already exists. * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public void clonePublisher(Admin admin, String oldname, String newname) { debug(">clonePublisher(name: " + oldname + ")"); BasePublisher publisherdata = null; try { PublisherDataLocal htp = publisherhome.findByName(oldname); publisherdata = (BasePublisher) htp.getPublisher().clone(); try { addPublisher(admin, newname, publisherdata); String msg = intres.getLocalizedMessage("publisher.clonedpublisher", newname, oldname); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, msg); } catch (PublisherExistsException f) { String msg = intres.getLocalizedMessage("publisher.errorclonepublisher", newname, oldname); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, msg); throw f; } } catch (Exception e) { String msg = intres.getLocalizedMessage("publisher.errorclonepublisher", newname, oldname); error(msg, e); throw new EJBException(e); } debug("<clonePublisher()"); } // clonePublisher /** * Removes a publisher from the database. * * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public void removePublisher(Admin admin, String name) { debug(">removePublisher(name: " + name + ")"); try { PublisherDataLocal htp = publisherhome.findByName(name); htp.remove(); String msg = intres.getLocalizedMessage("publisher.removedpublisher", name); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, msg); } catch (Exception e) { String msg = intres.getLocalizedMessage("publisher.errorremovepublisher", name); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, msg, e); } debug("<removePublisher()"); } // removePublisher /** * Renames a publisher * * @throws PublisherExistsException if publisher already exists. * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public void renamePublisher(Admin admin, String oldname, String newname) throws PublisherExistsException { debug(">renamePublisher(from " + oldname + " to " + newname + ")"); boolean success = false; try { publisherhome.findByName(newname); } catch (FinderException e) { try { PublisherDataLocal htp = publisherhome.findByName(oldname); htp.setName(newname); success = true; } catch (FinderException g) { } } if (success) { String msg = intres.getLocalizedMessage("publisher.renamedpublisher", oldname, newname); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_INFO_PUBLISHERDATA, msg); } else { String msg = intres.getLocalizedMessage("publisher.errorrenamepublisher", oldname, newname); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_PUBLISHERDATA, msg); } if (!success) throw new PublisherExistsException(); debug("<renamePublisher()"); } // renameHardTokenProfile /** * Retrives a Collection of id:s (Integer) to authorized publishers. * * @return Collection of id:s (Integer) * @ejb.interface-method view-type="both" */ public Collection getAuthorizedPublisherIds(Admin admin) { HashSet returnval = new HashSet(); Collection result = null; boolean superadmin = false; // If superadmin return all available publishers try { superadmin = getAuthorizationSession().isAuthorizedNoLog(admin, AvailableAccessRules.ROLE_SUPERADMINISTRATOR); result = this.publisherhome.findAll(); Iterator i = result.iterator(); while (i.hasNext()) { PublisherDataLocal next = (PublisherDataLocal) i.next(); returnval.add(next.getId()); } } catch (AuthorizationDeniedException e1) { log.debug("AuthorizationDeniedException: ", e1); } catch (FinderException fe) { log.error("FinderException looking for all publishers: ", fe); } // If CA-admin return publishers he is authorized to if (!superadmin) { Iterator authorizedcas = this.getAuthorizationSession().getAuthorizedCAIds(admin).iterator(); while (authorizedcas.hasNext()) { returnval.addAll(this.getCAAdminSession().getCAInfo(admin, ((Integer) authorizedcas.next()).intValue()).getCRLPublishers()); } } return returnval; } // getAuthorizedPublisherIds /** * Method creating a hashmap mapping publisher id (Integer) to publisher name (String). * * @ejb.transaction type="Supports" * @ejb.interface-method view-type="both" */ public HashMap getPublisherIdToNameMap(Admin admin) { HashMap returnval = new HashMap(); Collection result = null; try { result = publisherhome.findAll(); Iterator i = result.iterator(); while (i.hasNext()) { PublisherDataLocal next = (PublisherDataLocal) i.next(); returnval.put(next.getId(), next.getName()); } } catch (FinderException e) { } return returnval; } // getPublisherIdToNameMap /** * Retrives a named publisher. * * @ejb.transaction type="Supports" * @ejb.interface-method view-type="both" */ public BasePublisher getPublisher(Admin admin, String name) { BasePublisher returnval = null; try { returnval = (publisherhome.findByName(name)).getPublisher(); } catch (FinderException e) { // return null if we cant find it } return returnval; } // getPublisher /** * Finds a publisher by id. * * @ejb.transaction type="Supports" * @ejb.interface-method view-type="both" */ public BasePublisher getPublisher(Admin admin, int id) { BasePublisher returnval = null; try { returnval = (publisherhome.findByPrimaryKey(new Integer(id))).getPublisher(); } catch (FinderException e) { // return null if we cant find it } return returnval; } // getPublisher /** * Help method used by publisher proxys to indicate if it is time to * update it's data. * * @ejb.transaction type="Supports" * @ejb.interface-method view-type="both" */ public int getPublisherUpdateCount(Admin admin, int publisherid) { int returnval = 0; try { returnval = (publisherhome.findByPrimaryKey(new Integer(publisherid))).getUpdateCounter(); } catch (FinderException e) { } return returnval; } /** * Returns a publisher id, given it's publishers name * * @return the id or 0 if the publisher cannot be found. * @ejb.transaction type="Supports" * @ejb.interface-method view-type="both" */ public int getPublisherId(Admin admin, String name) { int returnval = 0; try { Integer id = (publisherhome.findByName(name)).getId(); returnval = id.intValue(); } catch (FinderException e) { } return returnval; } // getPublisherId /** * Returns a publishers name given its id. * * @return the name or null if id doesnt exists * @throws EJBException if a communication or other error occurs. * @ejb.transaction type="Supports" * @ejb.interface-method view-type="both" */ public String getPublisherName(Admin admin, int id) { debug(">getPublisherName(id: " + id + ")"); String returnval = null; PublisherDataLocal htp = null; try { htp = publisherhome.findByPrimaryKey(new Integer(id)); if (htp != null) { returnval = htp.getName(); } } catch (FinderException e) { } debug("<getPublisherName()"); return returnval; } // getPublisherName private Integer findFreePublisherId() { Random ran = (new Random((new Date()).getTime())); int id = ran.nextInt(); boolean foundfree = false; while (!foundfree) { try { if (id > 1) publisherhome.findByPrimaryKey(new Integer(id)); id = ran.nextInt(); } catch (FinderException e) { foundfree = true; } } return new Integer(id); } // findFreePublisherId} // LocalPublisherSessionBean
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -