Package org.wso2.carbon.bam.core.admin

Source Code of org.wso2.carbon.bam.core.admin.BAMDataServiceAdmin

/**
* Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wso2.carbon.bam.core.admin;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.bam.common.clients.BAMConfigurationDSClient;
import org.wso2.carbon.bam.common.clients.BAMDataCollectionDSClient;
import org.wso2.carbon.bam.common.dataobjects.activity.*;
import org.wso2.carbon.bam.common.dataobjects.mediation.ServerUserDefinedDO;
import org.wso2.carbon.bam.common.dataobjects.service.*;
import org.wso2.carbon.bam.core.persistence.BAMPersistenceManager;
import org.wso2.carbon.bam.core.util.BAMConfigurationCache;
import org.wso2.carbon.bam.core.util.BAMUtil;
import org.wso2.carbon.bam.util.BAMException;

public class BAMDataServiceAdmin {
    private static final Log log = LogFactory.getLog(BAMDataServiceAdmin.class); //TODO: Improve logging in this class

    public void addServerStatistics(ServerStatisticsDO statisticsDO) throws BAMException {
      BAMDataCollectionDSClient client = null;
      try {
        client = BAMUtil.getBAMDataCollectionDSClient();
        client.addServerData(statisticsDO);
      } catch (BAMException e) {
        throw e;
      } finally {
      if (client != null) {
          client.cleanup();
      }
    }
    }

    public void addServiceStatistics(ServiceStatisticsDO statisticsDO) throws BAMException {
        // Add the service if it doesn't exist
        BAMPersistenceManager pm = BAMPersistenceManager.getPersistenceManager(BAMUtil.getRegistry());
        int serviceId = statisticsDO.getServiceID();
        ServiceDO serviceDO;
        if (serviceId > 0) {
            serviceDO = pm.getService(serviceId);

        } else {
            serviceDO = pm.getService(statisticsDO.getServerID(), statisticsDO.getServiceName());
            statisticsDO.setServiceID(serviceDO.getId());
        }

        BAMDataCollectionDSClient client = null;
      try {
        client = BAMUtil.getBAMDataCollectionDSClient();
        client.addServiceData(statisticsDO);
      } finally {
      if (client != null) {
          client.cleanup();
      }
    }
    }

    public void addOperationStatistics(OperationStatisticsDO statisticsDO) throws BAMException {
        BAMPersistenceManager pm = BAMPersistenceManager.getPersistenceManager(BAMUtil.getRegistry());
        int operationId = statisticsDO.getOperationID();
        OperationDO operationDO;
        ServiceDO service;

        int serviceID = statisticsDO.getServiceID();
        if (serviceID > 0) {
            service = pm.getService(serviceID);
        } else {
            service = pm.getService(statisticsDO.getServerID(), statisticsDO.getServiceName());
            statisticsDO.setServiceID(service.getId());
        }

        if (operationId > 0) {
            operationDO = pm.getOperation(operationId);
        } else {
            operationDO = pm.getOperation(statisticsDO.getServiceID() ,statisticsDO.getOperationName());
            statisticsDO.setOperationID(operationDO.getOperationID());
        }

        BAMDataCollectionDSClient client = null;
      try {
        client = BAMUtil.getBAMDataCollectionDSClient();
        client.addOperationData(statisticsDO);
      } finally {
      if (client != null) {
          client.cleanup();
      }
    }
    }

    public void addServerData(ServerStatisticsDO statisticsDO) throws BAMException {
        BAMDataCollectionDSClient client = null;
      try {
        client = BAMUtil.getBAMDataCollectionDSClient();
        client.addServerData(statisticsDO);
      } finally {
      if (client != null) {
          client.cleanup();
      }
    }
    }

    public void addServerUserDefinedData(ServerUserDefinedDO statisticsDO) throws BAMException {
        BAMDataCollectionDSClient client = null;
      try {
        client = BAMUtil.getBAMDataCollectionDSClient();
        client.addServerUserDefinedData(statisticsDO);
      } finally {
      if (client != null) {
          client.cleanup();
      }
    }
    }
    /*
       * Add activity to the DB
       */
      public void addActivityData(ActivityDO activityDO) throws BAMException {

          BAMDataCollectionDSClient client = null;
          try {
              client = BAMUtil.getBAMDataCollectionDSClient();
              client.addActivityData(activityDO);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void addMessage(MessageDO messageDO) throws BAMException {
          BAMDataCollectionDSClient client = null;
          try {
              client = BAMUtil.getBAMDataCollectionDSClient();
              client.addMessageData(messageDO);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      /*
       * Add message to the DB.
       */
      public void addMessageData(MessageDO messageDO) throws BAMException {

          BAMDataCollectionDSClient client = null;
          try {
              client = BAMUtil.getBAMDataCollectionDSClient();
              client.addMessageData(messageDO);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      /*
       * Add message data to the DB.
       */
      public void addMessageDataDump(MessageDataDO messageDataDO,String direction) throws BAMException {
          BAMDataCollectionDSClient client = null;
          try {
              client = BAMUtil.getBAMDataCollectionDSClient();
              client.addMessageDataDump(messageDataDO,direction);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      /*
      * Add message Property data to the DB.
      */
      public void addMessageProperty(MessagePropertyDO messagePropertyDO)
              throws BAMException {
          BAMDataCollectionDSClient client = null;
          try {
              client = BAMUtil.getBAMDataCollectionDSClient();
              client.addMessageProperty(messagePropertyDO);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      /*
       * Add Operation user defined data.
       */
      public void addUserDefinedOperationData(OperationUserDefinedDO statisticsDO)
              throws BAMException {
          BAMDataCollectionDSClient client = null;
          try {
              client = BAMUtil.getBAMDataCollectionDSClient();
              client.addUserDefinedOperationData(statisticsDO);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }


      public void addService(ServiceDO serviceDO) throws BAMException {

          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.addService(serviceDO);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public ServiceDO getService(int serverID, String serviceName) throws BAMException {
          ServiceDO service = BAMConfigurationCache.getService(serverID, serviceName);
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              service = client.getService(serverID, serviceName);
              if (service != null) {
                  BAMConfigurationCache.addService(serverID,service);
              }
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
          return service;
      }

    /**
     *
     * @param serverUrl
     * @param tenantId
     * @return
     * @throws BAMException
     */
      public ServerDO getServer(String serverUrl, int tenantId,String serverType,int category) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              return client.getServer(serverUrl, tenantId,serverType,category);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public ServerDO getServer(String serverUrl) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              return client.getServer(serverUrl);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }


      public void addOperation(OperationDO operation) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.addOperation(operation);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public OperationDO getOperation(int serviceID, String operationName) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              return client.getOperation(serviceID, operationName);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public ActivityDO getActivityForActivityID(String activityID) throws BAMException {
          ActivityDO activityDO = BAMConfigurationCache.getActivity(activityID);
          if(activityDO == null){
              BAMConfigurationDSClient client = null;
              try {
                  client = BAMUtil.getBAMConfigurationDSClient();
                  activityDO = client.getActivityForActivityID(activityID);
                  if(activityDO != null){
                      BAMConfigurationCache.addActivity(activityID, activityDO);
                  }
              } catch (BAMException e) {
                  throw e;
              } finally {
                  if (client != null) {
                      client.cleanup();
                  }
              }
          }
          return activityDO;
      }

      public void addActivity(ActivityDO activity) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.addActivity(activity);
              BAMConfigurationCache.addActivity(activity.getActivityKeyId(), activity);
              BAMConfigurationCache.addActivity(activity.getActivityId(), activity);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public MessageDO getMessage(String messageId,int operationId, int activityKeyId) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              return client.getMessage(messageId,operationId,activityKeyId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public MessageDataDO getMessageDataForActivityKeyIDandMessageKeyID(int messageKeyID,
                                                                         int activityKeyID)
              throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              return client.getMessageDataForActivityKeyIDandMessageKeyID(messageKeyID, activityKeyID);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void updateMessageStatus(String messageStatus, int messageDataKeyId) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.updateMessageStatus(messageStatus, messageDataKeyId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void updateActivity(String name, String description, int activityKeyId)
              throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.updateActivity(name, description, activityKeyId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void updateMessageDump(String messageBody, String messageDir, String ipAddress, int messageDataKeyId)
          throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.updateMessageDump(messageBody, messageDir, ipAddress, messageDataKeyId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }
      public MessagePropertyDO getPropertyofMessage(int messageKeyId, int activityKeyId, String key) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              return client.getPropertyofMessage(messageKeyId, activityKeyId, key);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public PropertyFilterDO getXpathConfiguration(String xpathKey, int serverId)
              throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              return client.getXpathData(xpathKey, serverId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void addXpathConfiguration(String alias, String xpathKey, String expression, int serverId)
              throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.addXpathData(alias, xpathKey, expression, serverId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void updateXpathConfiguration(String alias, String xpathKey, String expression,
                                           int serverId, int bamId) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.updateXpathData(alias, xpathKey, expression, serverId, bamId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void addNamespaceData(int xpathId, String prefix, String uri) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.addNamespaceData(xpathId, prefix, uri);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

      public void deleteNamespaceData(int xpathId) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.deleteNamespaceData(xpathId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }
      public void updateMessageProperty(String value, int messagePropertyKeyId) throws BAMException {
          BAMConfigurationDSClient client = null;
          try {
              client = BAMUtil.getBAMConfigurationDSClient();
              client.updateMessageProperty(value, messagePropertyKeyId);
          } catch (BAMException e) {
              throw e;
          } finally {
              if (client != null) {
                  client.cleanup();
              }
          }
      }

  }
TOP

Related Classes of org.wso2.carbon.bam.core.admin.BAMDataServiceAdmin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.