Examples of ISbiAttributeDAO


Examples of it.eng.spagobi.profiling.dao.ISbiAttributeDAO

    logger.debug("IN");
    try {
      _config= config;
      /* loads default users , attributes reading from xml*/
      List defaultAttributes = _config.getAttributeAsList("DEFAULT_ATTRIBUTES.ATTRIBUTE");
      ISbiAttributeDAO attrDAO= DAOFactory.getSbiAttributeDAO();
     
      //hashmap to use during
      HashMap< String, Integer> attributesLookup = new HashMap< String, Integer> ();
      for (int i=0; i<defaultAttributes.size();i++) {
          SourceBean attribute = (SourceBean) defaultAttributes.get(i);
         
          SbiAttribute sbiAttribute = new SbiAttribute();
          String attrName = (String) attribute.getAttribute("name");
         
          SbiAttribute existingAttribute = attrDAO.loadSbiAttributeByName(attrName);
          if(existingAttribute == null){
            sbiAttribute.setAttributeName(attrName);
            String attrDescr = (String) attribute.getAttribute("description");
            sbiAttribute.setDescription(attrDescr);         
           
            try
              Integer id = attrDAO.saveSbiAttribute(sbiAttribute);
              attributesLookup.put(attrName, id);
          } catch (EMFUserError e) {
            logger.error(e.getMessage(), e);
         
          }else{
View Full Code Here

Examples of it.eng.spagobi.profiling.dao.ISbiAttributeDAO

  private static Logger logger = Logger.getLogger(ManageAttributesAction.class);
 
  @Override
  public void doService() {
    logger.debug("IN");
    ISbiAttributeDAO attrDao;
    try {
      attrDao = DAOFactory.getSbiAttributeDAO();
      attrDao.setUserProfile(getUserProfile());
    } catch (EMFUserError e1) {
      logger.error(e1.getMessage(), e1);
      throw new SpagoBIServiceException(SERVICE_NAME,  "Error occurred");
    }
    HttpServletRequest httpRequest = getHttpRequest();

    Locale locale = getLocale();

    String serviceType = this.getAttributeAsString(MESSAGE_DET);
    logger.debug("Service type "+serviceType);
   
    if (serviceType != null && serviceType.contains(ATTR_LIST)) {
      String name = null;
      String description =null;
      String idStr = null;
      try {
        BufferedReader b =httpRequest.getReader();
        if(b!=null){
          String respJsonObject = b.readLine();
          if(respJsonObject!=null){
            JSONObject responseJSON = deserialize(respJsonObject);
            JSONObject samples = responseJSON.getJSONObject(SAMPLES);
            if(!samples.isNull(ID)){
              idStr = samples.getString(ID);
            }
           
            //checks if it is empty attribute to start insert
            boolean isNewAttr = this.getAttributeAsBoolean(IS_NEW_ATTR);

            if(!isNewAttr){
              if(!samples.isNull(NAME)){
               
                name = samples.getString(NAME);
                if (GenericValidator.isBlankOrNull(name) ||
                    !GenericValidator.matchRegexp(name, ALPHANUMERIC_STRING_REGEXP_NOSPACE)||
                      !GenericValidator.maxLength(name, nameMaxLenght)){
                  logger.error("Either the field name is blank or it exceeds maxlength or it is not alfanumeric");
                  EMFValidationError e = new EMFValidationError(EMFErrorSeverity.ERROR, description, "9000","");
                  getHttpResponse().setStatus(404)
                  JSONObject attributesResponseSuccessJSON = new JSONObject();
                  attributesResponseSuccessJSON.put("success", false);
                  attributesResponseSuccessJSON.put("message", "Either the field name is blank or it exceeds maxlength or it is not alfanumeric");
                  attributesResponseSuccessJSON.put("data", "[]");
                 
                  writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );

                  return;
 
                }
              }
              if(!samples.isNull(DESCRIPTION)){
                description = samples.getString(DESCRIPTION);
 
                if (GenericValidator.isBlankOrNull(description) ||
                    !GenericValidator.matchRegexp(description, ALPHANUMERIC_STRING_REGEXP_NOSPACE) ||
                        !GenericValidator.maxLength(description, descriptionMaxLenght)){
                  logger.error("Either the field description is blank or it exceeds maxlength or it is not alfanumeric");
 
                  EMFValidationError e = new EMFValidationError(EMFErrorSeverity.ERROR, description, "9000","");
                  getHttpResponse().setStatus(404)
                  JSONObject attributesResponseSuccessJSON = new JSONObject();
                  attributesResponseSuccessJSON.put("success", false);
                  attributesResponseSuccessJSON.put("message", "Either the field description is blank or it exceeds maxlength or it is not alfanumeric");
                  attributesResponseSuccessJSON.put("data", "[]");
                  writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) );
                  return;
                }
              }
           
              SbiAttribute attribute = new SbiAttribute();
              if(description!=null){
                attribute.setDescription(description);
              }
              if(name!=null){
                attribute.setAttributeName(name);
              }
              boolean isNewAttrForRes = true;
              if(idStr!=null && !idStr.equals("")){
                Integer attributeId = new Integer(idStr);
                attribute.setAttributeId(attributeId.intValue());
                isNewAttrForRes = false;
              }
              Integer attrID = attrDao.saveOrUpdateSbiAttribute(attribute);
              logger.debug("Attribute updated");

              ArrayList<SbiAttribute> attributes = new ArrayList<SbiAttribute> ();
              attribute.setAttributeId(attrID);
              attributes.add(attribute);
             
              getAttributesListAdded(locale,attributes,isNewAttrForRes, attrID);

            }
            //else the List of attributes will be sent to the client
          }else{
            getAttributesList(locale,attrDao);
          }
        }else{
          getAttributesList(locale,attrDao);
        }

      } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        getHttpResponse().setStatus(404);               
        try {
          JSONObject attributesResponseSuccessJSON = new JSONObject();
          attributesResponseSuccessJSON.put("success", true);
          attributesResponseSuccessJSON.put("message", "Exception occurred while saving attribute");
          attributesResponseSuccessJSON.put("data", "[]");
          writeBackToClient( new JSONSuccess(attributesResponseSuccessJSON) )
        } catch (IOException e1) {
          logger.error(e1.getMessage(), e1);
        } catch (JSONException e2) {
          logger.error(e2.getMessage(), e2);
        }
        throw new SpagoBIServiceException(SERVICE_NAME,
            "Exception occurred while retrieving attributes", e);
      }
    } else if (serviceType != null  && serviceType.equalsIgnoreCase(ATTR_DELETE)) {
     
      String idStr = null;
      try {
        BufferedReader b =httpRequest.getReader();
        if(b!=null){
          String respJsonObject = b.readLine();
          if(respJsonObject!=null){
            JSONObject responseJSON = deserialize(respJsonObject);
            idStr = responseJSON.getString(SAMPLES);
          }
        }
       
      } catch (IOException e1) {
        logger.error("IO Exception",e1);
        e1.printStackTrace();
      } catch (SerializationException e) {
        logger.error("Deserialization Exception",e);
        e.printStackTrace();
      } catch (JSONException e) {
        logger.error("JSONException",e);
        e.printStackTrace();
      }
      if(idStr!=null && !idStr.equals("")){
        Integer id = new Integer(idStr);
        try {
          attrDao.deleteSbiAttributeById(id);
          logger.debug("Attribute deleted");
          JSONObject attributesResponseSuccessJSON = new JSONObject();
          attributesResponseSuccessJSON.put("success", true);
          attributesResponseSuccessJSON.put("message", "");
          attributesResponseSuccessJSON.put("data", "[]");
View Full Code Here
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.