List of usage examples for org.hibernate Session saveOrUpdate
void saveOrUpdate(Object object);
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @param priceReport/*from w ww . ja v a 2s .c o m*/ * @param customerIdStr * @throws NamingException * @throws HibernateException */ public static void approvePriceReport(PriceReport priceReport, String remoteUser) throws HibernateException, NamingException, Exception { Customer customer = CustomerReadDelegate .getCustomerByAccountNumber(priceReport.getAccountNumber().longValue()); MisldAccountSettings misldAccountSettings = customer.getMisldAccountSettings(); PriceReportCycle priceReportCycle = getActivePriceReportCycle(customer); if (priceReportCycle == null) { priceReportCycle = new PriceReportCycle(); createPriceReportArchive(customer, priceReport, Constants.APPROVED, remoteUser); } else { priceReportCycle.setApprovalTime(new Date()); priceReportCycle.setApprover(remoteUser); priceReportCycle.setCycleStatus(Constants.APPROVED); priceReportCycle.setPriceReportStatus(Constants.APPROVED); priceReportCycle.setPriceReportStatusUser(remoteUser); priceReportCycle.setPriceReportStatusTimestamp(new Date()); } // createPriceReportArchive(customer, priceReport, Constants.APPROVED, // remoteUser); Session session = getHibernateSession(); Transaction tx = session.beginTransaction(); // session.saveOrUpdate(priceReportCycle); Notification notification = NotificationDelegate.getNotificationByCustomerTypeStatus(customer, Constants.PRICE_REPORT, Constants.ACTIVE); boolean sameNotifier = false; if ((notification != null)) { String notifier = notification.getRemoteUser(); if (notifier.equals(remoteUser)) sameNotifier = true; // If the Price Report is approved, set the notification status to // Inactive // so that the account is not escalated notification.setStatus(Constants.INACTIVE); session.update(notification); // If the person who sent the Price Report notification to the DPE // is the person // who approved the report, send an email to the management chain if (sameNotifier && (customer != null)) { Customer[] c = new Customer[1]; c[0] = customer; Contact dpe = new Contact(); String dpe_serial = null; String dpe_email = null; Contact manager = new Contact(); String manager_serial = null; String manager_email = null; Contact director = new Contact(); String director_serial = null; String director_email = null; Contact vp = new Contact(); String vp_serial = null; String vp_email = null; dpe = customer.getContactDPE(); dpe_serial = dpe.getSerial(); dpe = BluegroupsDelegate.getContactByLongSerial(dpe_serial); dpe_email = dpe.getRemoteUser(); manager_serial = dpe.getManagerSerial(); if (manager_serial != null) { manager = BluegroupsDelegate.getContactByLongSerial(manager_serial); manager_email = manager.getRemoteUser(); director_serial = manager.getManagerSerial(); if (director_serial != null) { director = BluegroupsDelegate.getContactByLongSerial(director_serial); director_email = director.getRemoteUser(); vp_serial = director.getManagerSerial(); if (vp_serial != null) { vp = BluegroupsDelegate.getContactByLongSerial(vp_serial); vp_email = vp.getRemoteUser(); } } } String[] toUsers = new String[2]; String[] ccUsers = new String[3]; toUsers[0] = director_email; toUsers[1] = vp_email; ccUsers[0] = dpe_email; ccUsers[1] = manager_email; ccUsers[2] = "srednick@us.ibm.com"; sendNotifications(c, remoteUser, notifier, toUsers, ccUsers, Constants.SW_ANALYST_APPROVAL); } } // Set the Account Settings so that the account is locked if (misldAccountSettings != null) { misldAccountSettings.setStatus(Constants.LOCKED); misldAccountSettings.setPriceReportStatus(Constants.APPROVED); misldAccountSettings.setPriceReportStatusUser(remoteUser); misldAccountSettings.setPriceReportTimestamp(new Date()); } session.update(misldAccountSettings); tx.commit(); session.close(); }
From source file:com.ibm.tap.misld.report.PriceReportDelegate.java
/** * @param s/*from ww w . j a v a 2s . c o m*/ * @param string * @throws Exception */ public static String sendNotifications(Customer[] s, String remoteUser, String notifier, String[] toUsers, String[] ccUsers, String notificationType) throws Exception { Session session = getHibernateSession(); Transaction tx = session.beginTransaction(); String pod = null; if (notifier == null) { notifier = "srednick@us.ibm.com"; } for (int i = 0; i < s.length; i++) { Customer formCustomer = (Customer) s[i]; if (((notificationType.equals(Constants.PRICE_REPORT)) && (formCustomer.getStatus().equals("on"))) || (!notificationType.equals(Constants.PRICE_REPORT))) { Customer customer = CustomerReadDelegate .getCustomerByLong(formCustomer.getCustomerId().longValue()); pod = customer.getPod().getPodId().toString(); Notification notification = NotificationDelegate.getNotification(customer, notificationType); if (notification == null) { notification = new Notification(); notification.setCustomer(customer); notification.setNotificationType(notificationType); } notification.setRemoteUser(remoteUser); notification.setStatus(Constants.ACTIVE); notification.setRecordTime(new Date()); session.saveOrUpdate(notification); StringBuffer content = new StringBuffer(); ArrayList topeeps = new ArrayList(); String toUser = null; if (toUsers != null) { for (int u = 0; u < toUsers.length; u++) { toUser = (String) toUsers[u]; topeeps.add(toUser); } } ArrayList ccpeeps = new ArrayList(); String ccUser = null; if (ccUsers != null) { for (int c = 0; c < ccUsers.length; c++) { ccUser = (String) ccUsers[c]; ccpeeps.add(ccUser); } } // Add notifier email to each notification if (!remoteUser.equals("mswiz@tap.raleigh.ibm.com")) { ccpeeps.add(remoteUser); } String subject = ""; // MisldDate currentQtrRecord = // MisldDateReadDelegate.getCurrentQtr(); String currentQtr = "4Q"; // String currentQtr = currentQtrRecord.getDateValue(); if (notificationType == Constants.PRICE_REPORT) { topeeps.add(customer.getContactDPE().getRemoteUser()); subject = "URGENT: Action Required within 5 business days: Microsoft Price Report Notification"; content.append("DPE,\n\n"); content.append( "You are required to take action within 5 business days of this notification.\n"); content.append("Summary of Action Items that Need to Be Completed within 5 business days:\n\n"); content.append("1. Log into the Microsoft Wizard to review " + customer.getCustomerName() + " account's Microsoft pricing report.\n"); content.append( "2. If any changes are needed, please click the REJECT button and notify your SW asset management analyst of the changes, who is also copied on this note. " + "The SW analyst will make any updates needed and then resubmit the pricing report for your review.\n"); content.append( "3. Once you agree with the pricing report, please click the APPROVE button.\n"); content.append( "4. If you fail to respond within 5 business days, your manager will be notified. You will then have an additional " + "3 days to review the report. If you do not do so, your Director and VP will be notified and a PO will be cut " + "against the " + customer.getCustomerName() + " account's " + currentQtr + " Microsoft SPLA payment.\n\n"); content.append("Detailed Instructions:\n\n"); content.append( "Asset Management has collected the Microsoft data found in the Microsoft Wizard for your account. " + "Please click on the following link to be taken to your account's pricing report in the Microsoft Wizard: " + "https://bravo.boulder.ibm.com/BRAVO/MsWizard/PriceReport.do?customer=" + customer.getCustomerId() + "\n\n"); content.append( "If the following link does not work, please follow these instructions to be taken to your account's price report:\n"); content.append( "1. Access https://bravo.boulder.ibm.com/BRAVO/mswiz.do. Login with your intranet ID and password.\n"); content.append("2. Click on the Reports link on the left.\n"); content.append( "3. Click on the following department: " + customer.getPod().getPodName() + "\n"); content.append( "4. To view your account's price report, click on view located to the right of your account's name.\n\n"); content.append( "If there is missing Microsoft SW information from this spreadsheet, please contact your SW asset management analyst, " + "who is also copied on this note, so that they can add missing information.\n\n"); content.append( "Please pay special attention to the Non-Operating System software (ex Office and SQL). " + "If any SW marked as IBM owned is really customer owned, please let your SW analyst know. " + "Also, if known, please provide the user count on each server. Unless we are provided the user count, " + "we assume 1000 users so that processor licenses are purchased. If you can provide the user count, " + "it's quite possible that you can save money as we may be able to pay for user licenses. " + "Also, please pay special attention to SQL Server and Office. The script used to collect the " + "SW inventory has caused false positives for this product in the past. Please ensure that any instances of " + "these products in your pricing report are correct.\n\n"); content.append( "Due to recent ASCA certification reviews of the MS Wizard, we are now required to show positive confirmation from the DPE or " + "escalation if there is no response from the DPE prior to sending price report with purchase orders to SHI. Because of the timeline " + "we are on with Microsoft it is imperative that you respond asap. If you fail to respond within the specified time, asset management " + "will lock down the report and notification will be sent to your Director and VP informing them that you have not responded to " + "these communications.\n\n"); content.append( "Please direct your questions or responses to your SW asset management analyst, who is copied on this note, or the Microsoft SPLA Focal, " + "Stacy Shanahan. Please do not respond to the mswiz@tap.raleigh.ibm.com address.\n\n"); } if (notificationType == Constants.ESCALATION) { subject = "Second Notice: URGENT: Action Required within 3 Business Days: Microsoft Price Report Notification"; content.append("Manager,\n\n"); content.append( "The DPE on copy has been notified that their action is required to review and approve the " + currentQtr + " Microsoft SPLA price report for the " + customer.getCustomerName() + " account. Our records indicate that the report has not been reviewed/approved. Please ensure that your employee does " + "so within the next 3 business days otherwise the report will be approved by the SW Asset Analyst and notification will be sent to their " + "Director and VP.\n\n"); content.append( "Please do not respond to the mswiz@tap.raleigh.ibm.com address. If you have any questions please contact " + notifier + " at " + ccUsers[1] + " .\n\n\n"); content.append( "Here is the notice originally sent to the DPE asking that they respond within 5 business days: \n"); content.append( "==============================================================================================\n\n"); content.append("DPE,\n\n"); content.append( "You are required to take action within 5 business days of this notification.\n"); content.append("Summary of Action Items that Need to Be Completed within 5 business days:\n\n"); content.append("1. Log into the Microsoft Wizard to review " + customer.getCustomerName() + " account's Microsoft pricing report.\n"); content.append( "2. If any changes are needed, please click the REJECT button and notify your SW asset management analyst of the changes, who is also copied on this note. " + "The SW analyst will make any updates needed and then resubmit the pricing report for your review.\n"); content.append( "3. Once you agree with the pricing report, please click the APPROVE button.\n"); content.append( "4. If you fail to respond within 5 business days, your manager will be notified. You will then have an additional " + "3 days to review the report. If you do not do so, your Director and VP will be notified and a PO will be cut " + "against the " + customer.getCustomerName() + " account's " + currentQtr + " Microsoft SPLA payment.\n\n"); content.append("Detailed Instructions:\n\n"); content.append( "Asset Management has collected the Microsoft data found in the Microsoft Wizard for your account. " + "Please click on the following link to be taken to your account's pricing report in the Microsoft Wizard: " + "https://bravo.boulder.ibm.com/BRAVO/MsWizard/PriceReport.do?customer=" + customer.getCustomerId() + "\n\n"); content.append( "If the following link does not work, please follow these instructions to be taken to your account's price report:\n"); content.append( "1. Access https://bravo.boulder.ibm.com/BRAVO/mswiz.do. Login with your intranet ID and password.\n"); content.append("2. Click on the Reports link on the left.\n"); content.append( "3. Click on the following department: " + customer.getPod().getPodName() + "\n"); content.append( "4. To view your account's price report, click on view located to the right of your account's name.\n\n"); content.append( "If there is missing Microsoft SW information from this spreadsheet, please contact your SW asset management analyst, " + "who is also copied on this note, so that they can add missing information.\n\n"); content.append( "Please pay special attention to the Non-Operating System software (ex Office and SQL). " + "If any SW marked as IBM owned is really customer owned, please let your SW analyst know. " + "Also, if known, please provide the user count on each server. Unless we are provided the user count, " + "we assume 1000 users so that processor licenses are purchased. If you can provide the user count, " + "it's quite possible that you can save money as we may be able to pay for user licenses. " + "Also, please pay special attention to SQL Server and Office. The script used to collect the " + "SW inventory has caused false positives for this product in the past. Please ensure that any instances of " + "these products in your pricing report are correct.\n\n"); content.append( "Due to recent ASCA certification reviews of the MS Wizard, we are now required to show positive confirmation from the DPE or " + "escalation if there is no response from the DPE prior to sending price report with purchase orders to SHI. Because of the timeline " + "we are on with Microsoft it is imperative that you respond asap. If you fail to respond within the specified time, asset management " + "will lock down the report and notification will be sent to your Director and VP informing them that you have not responded to " + "these communications.\n\n"); content.append( "Please direct your questions or responses to your SW asset management analyst, who is copied on this note, or the Microsoft SPLA Focal, " + "Stacy Shanahan. Please do not respond to the mswiz@tap.raleigh.ibm.com address.\n\n"); } if (notificationType == Constants.SW_ANALYST_APPROVAL) { subject = "URGENT: Microsoft SPLA Charges for the " + customer.getCustomerName() + " Account"; content.append("Director and VP,\n\n"); content.append( "The DPE on copy has been notified that their action is required to review and approve the " + currentQtr + " Microsoft SPLA price report for the " + customer.getCustomerName() + " account. Our records indicate that the report has not been reviewed/approved. This has already been escalated to their " + "Manager without success. The account has now been approved and the charges processed. \n\n"); content.append( "To view the charges for this account, please click on the following link to be taken to the account's pricing report in the Microsoft Wizard: " + "https://bravo.boulder.ibm.com/BRAVO/MsWizard/PriceReport.do?customer=" + customer.getCustomerId() + "\n\n"); content.append("Please do not respond to the mswiz@tap.raleigh.ibm.com address.\n\n"); } try { // *************** FOR TESTING // ******************************* // content.append("To: "); // for (int t = 0; t < topeeps.size(); t++) { // System.out.println("topeeps " + t + " = " + // topeeps.get(t)); // content.append(topeeps.get(t) + ", "); // } // content.append("\n\n"); // content.append("Cc: "); // for (int c = 0; c < ccpeeps.size(); c++) { // System.out.println("ccpeeps " + c + " = " + // ccpeeps.get(c)); // if (ccpeeps.get(c) != null) { // content.append(ccpeeps.get(c) + ", "); // } // } // content.append("\n\n"); // ArrayList to = new ArrayList(); // to.add("srednick@us.ibm.com"); // ArrayList cc = new ArrayList(); // cc.add("kneikirk@us.ibm.com"); // cc.add("cpereira@us.ibm.com"); // EmailDelegate.sendMessage(subject, to, cc, content); // System.out.println("== test emailing enabled =="); // *********************************************************** EmailDelegate.sendMessage(subject, topeeps, ccpeeps, content); } catch (Exception e) { e.printStackTrace(); throw e; } } } tx.commit(); session.close(); return pod; }
From source file:com.ikon.dao.RegisteredPropertyGroupDAO.java
License:Open Source License
/** * Create or update/*w w w .j ava 2s. c o m*/ */ public void createOrUpdate(RegisteredPropertyGroup rpg) throws DatabaseException { log.debug("create({})", rpg); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); session.saveOrUpdate(rpg); HibernateUtil.commit(tx); log.debug("create: void"); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.UserItemsDAO.java
License:Open Source License
/** * Update user items/*from w w w. j a v a 2 s .c o m*/ */ public static void update(UserItems ui) throws DatabaseException { log.debug("update({})", ui); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); session.saveOrUpdate(ui); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("update: void"); }
From source file:com.imos.hibernate.HibernateTest.java
private static void saveAndUpdate(final Session session, PersonDetails ud) { session.beginTransaction();//w ww. j a v a 2s.com ud.setUpdatedTime(new Date()); session.saveOrUpdate(ud); session.getTransaction().commit(); }
From source file:com.indicator_engine.dao.UserCredentialsDaoImpl.java
License:Open Source License
@Transactional public void update(UserCredentials uc) { Session session = factory.getCurrentSession(); session.saveOrUpdate(uc); }
From source file:com.inventory.system.dao.AcademicClassDAOImpl.java
@Override public AcademicClass addClass(AcademicClass object) { Session session = HibernateBDUtil.getSessionFactory().openSession(); Transaction tx = null;/*from w ww.j a v a2 s . c o m*/ try { tx = session.beginTransaction(); session.saveOrUpdate(object); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); ex.printStackTrace(); } } finally { session.close(); } return object; }
From source file:com.inventory.system.dao.AdminDAOImpl.java
@Override public Admin addUser(Admin admin) { Session session = HibernateBDUtil.getSessionFactory().openSession(); Transaction tx = null;// w w w . j ava2 s . c om try { tx = session.beginTransaction(); session.saveOrUpdate(admin); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); ex.printStackTrace(); } } finally { session.close(); } return admin; }
From source file:com.inventory.system.dao.AuditTrailDAOImpl.java
@Override public AuditTrail addTrail(AuditTrail trail) { Session session = HibernateBDUtil.getSessionFactory().openSession(); Transaction tx = null;// w ww . jav a 2 s . c o m try { tx = session.beginTransaction(); session.saveOrUpdate(trail); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); ex.printStackTrace(); } } finally { session.close(); } return trail; }
From source file:com.inventory.system.dao.LocalGovernmentDAOImpl.java
@Override public LocalGovernment addLocalGovernment(LocalGovernment local) { Session session = HibernateBDUtil.getSessionFactory().openSession(); Transaction tx = null;/* w w w .ja v a 2s. c om*/ try { tx = session.beginTransaction(); session.saveOrUpdate(local); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); ex.printStackTrace(); } } finally { session.close(); } return local; }