C Common Utility Code Examples
This appendix provides example code of common utilities that are often used when working with the Oracle Communications Unified Inventory Management (UIM) application program interfaces (APIs).
Example C-1 Common Utility Code
public boolean hasErrors() { boolean hasErrors = false; UserEnvironment userEnvironment = UserEnvironmentFactory.getUserEnvironment(); if (userEnvironment != null) { FeedbackProvider feedbackProvider = userEnvironment.getFeedbackProvider(); hasErrors = feedbackProvider.hasMessages(FeedbackLevel.ERROR); } return hasErrors; } public FeedbackProvider getFeedbackProvider() { FeedbackProvider feedbackProvider = null; UserEnvironment userEnvironment = getUserEnvironment(); if (userEnvironment != null) { feedbackProvider = userEnvironment.getFeedbackProvider(); } return feedbackProvider; } protected static void commitOrRollback(UserTransaction ut)throws Exception { FeedbackProvider feedbackProvider = getUserEnvironment().getFeedbackProvider(); if (feedbackProvider.hasMessages(FeedbackLevel.ERROR)) { if (ut != null && ut.getStatus() == Status.STATUS_ACTIVE) ut.rollback(); } else { if (ut != null && ut.getStatus() == Status.STATUS_ACTIVE) ut.commit(); } } protected static UserEnvironment startUserEnvironment()throws Exception { UserEnvironment userEnvironment = null; try { UserEnvironment = getUserEnvironment(); if (userEnvironment != null) { //Reset the User Context in User Environment. userEnvironment.reset(); //Begin the UserEnvironment before it is first used. userEnvironment.begin(); //Reset the Feedback Provider in User Environment. userEnvironment.getFeedbackProvider().reset(); } } catch (Exception e) { e.printStackTrace(); throw e; } return userEnvironment; } protected static void endUserEnvironment(UserEnvironment userEnvironment) { if (userEnvironment == null) return; userEnvironment.getFeedbackProvider().reset(); userEnvironment.end();} protected static UserEnvironment getUserEnvironment() throws Exception { UserEnvironment userEnvironment = null; try { //Utils is oracle.communications.platform.util.Utils InitialContext initialContext = Utils.getInitialContext(); String jndiContextName = "inv"; String userEnvironmentName = "UserEnvironment"; userEnvironment = (UserEnvironment)initialContext.lookup (jndiContextName + "/" + userEnvironmentName); initialContext.close(); } catch (Exception e) { e.printStackTrace(); throw e; } return userEnvironment; }