public ArrayList<ServiceInfo> getServices(Properties properties) throws ApiException {
   ArrayList<ServiceInfo> services = new ArrayList<ServiceInfo>();
   try {
     String defaultLangCode = this.getLangManager().getDefaultLang().getCode();
     String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
     String tagParamValue = properties.getProperty("tag");
     String myentandoParamValue = properties.getProperty("myentando");
     Boolean myentando =
         (null != myentandoParamValue && myentandoParamValue.trim().length() > 0)
             ? Boolean.valueOf(myentandoParamValue)
             : null;
     langCode =
         (null != langCode && null != this.getLangManager().getLang(langCode))
             ? langCode
             : defaultLangCode;
     Map<String, ApiService> masterServices =
         this.getApiCatalogManager().getServices(tagParamValue, myentando);
     Iterator<ApiService> iter = masterServices.values().iterator();
     while (iter.hasNext()) {
       ApiService service = (ApiService) iter.next();
       if (service.isActive()
           && !service.isHidden()
           && this.checkServiceAuthorization(service, properties, false)) {
         ServiceInfo smallService = this.createServiceInfo(service, langCode, defaultLangCode);
         services.add(smallService);
       }
     }
     BeanComparator comparator = new BeanComparator("description");
     Collections.sort(services, comparator);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "getServices", "Error extracting services");
     throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
   }
   return services;
 }
 public Map<String, ApiService> getServices(String tag, Boolean myentando)
     throws ApsSystemException {
   Map<String, ApiService> services = this.getServices();
   if ((null == tag || tag.trim().length() == 0) && null == myentando) {
     return services;
   }
   Map<String, ApiService> servicesToReturn = new HashMap<String, ApiService>();
   try {
     Iterator<ApiService> iter = services.values().iterator();
     while (iter.hasNext()) {
       ApiService apiService = iter.next();
       String serviceTag = apiService.getTag();
       boolean tagCheck =
           (null == tag
               || (null != serviceTag
                   && serviceTag.toLowerCase().indexOf(tag.trim().toLowerCase()) > -1));
       boolean myentandoCheck =
           (null == myentando || (myentando.booleanValue() == apiService.isMyEntando()));
       if (tagCheck && myentandoCheck) {
         servicesToReturn.put(apiService.getKey(), apiService);
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "getServices", "Error extracting services");
     throw new ApsSystemException("Error extracting services", t);
   }
   return servicesToReturn;
 }
 protected ServiceInfo createServiceInfo(
     ApiService service, String langCode, String defaultLangCode) {
   String description = service.getDescription().getProperty(langCode);
   if (null == description || description.trim().length() == 0) {
     description = service.getDescription().getProperty(defaultLangCode);
   }
   ServiceInfo smallService =
       new ServiceInfo(service.getKey(), description, service.getTag(), service.isMyEntando());
   String[] freeParameters = service.getFreeParameters();
   if (null != freeParameters && freeParameters.length > 0) {
     for (int i = 0; i < freeParameters.length; i++) {
       String freeParameter = freeParameters[i];
       ApiMethodParameter apiParameter = service.getMaster().getParameter(freeParameter);
       if (null != apiParameter) {
         ServiceParameterInfo spi = new ServiceParameterInfo(apiParameter);
         ApsProperties serviceParameters = service.getParameters();
         String defaultValue =
             (null != serviceParameters) ? serviceParameters.getProperty(freeParameter) : null;
         if (null != defaultValue) {
           spi.setDefaultValue(defaultValue);
           spi.setRequired(false);
         }
         smallService.addParameter(spi);
       }
     }
   }
   return smallService;
 }
 public ApiService getApiService(String key) throws ApsSystemException {
   try {
     if (null == this.getMasterServices()) {
       this.loadServices();
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "getApiService", "Error extracting services");
     throw new ApsSystemException("Error extracting services", t);
   }
   ApiService service = this.getMasterServices().get(key);
   if (null == service) {
     return null;
   }
   return service.clone();
 }
 public void saveService(ApiService service) throws ApsSystemException {
   try {
     if (null == service) {
       throw new ApsSystemException("Null api service to save");
     }
     ApiMethod master = service.getMaster();
     if (null == master
         || null
             == this.getMethod(
                 master.getHttpMethod(), master.getNamespace(), master.getResourceName())) {
       throw new ApsSystemException("null or invalid master method of service to save");
     }
     if (null != this.getMasterServices().get(service.getKey())) {
       this.getApiCatalogDAO().updateService(service);
     } else {
       this.getApiCatalogDAO().addService(service);
     }
     this.getMasterServices().put(service.getKey(), service);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "saveService", "Error saving service");
     throw new ApsSystemException("Error saving service", t);
   }
 }
 public Object getService(Properties properties) throws ApiException {
   Object response = null;
   String key = (String) properties.get("key");
   try {
     ApiService service = this.getApiCatalogManager().getApiService(key);
     if (null == service) {
       throw new ApiException(
           IApiErrorCodes.API_SERVICE_INVALID, "Service '" + key + "' does not exist");
     }
     if (!service.isActive()) {
       throw new ApiException(
           IApiErrorCodes.API_SERVICE_ACTIVE_FALSE, "Service '" + key + "' is not active");
     }
     this.checkServiceAuthorization(service, properties, true);
     Properties serviceParameters = new Properties();
     serviceParameters.putAll(service.getParameters());
     Iterator<Object> paramIter = properties.keySet().iterator();
     List<String> reservedParameters = Arrays.asList(SystemConstants.API_RESERVED_PARAMETERS);
     while (paramIter.hasNext()) {
       Object paramName = paramIter.next();
       String paramNameString = paramName.toString();
       if (reservedParameters.contains(paramNameString)
           || service.isFreeParameter(paramNameString)) {
         serviceParameters.put(paramNameString, properties.get(paramName));
       }
     }
     response = this.getResponseBuilder().createResponse(service.getMaster(), serviceParameters);
   } catch (ApiException e) {
     throw e;
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t, this, "getService", "Error invocating service - key '" + key + "'");
     throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
   }
   return response;
 }
 public void updateService(ApiService service) throws ApsSystemException {
   try {
     if (null == service) {
       throw new ApsSystemException("Null api service to update");
     }
     ApiService masterService = this.getMasterServices().get(service.getKey());
     if (null == masterService) {
       throw new ApsSystemException("Api service '" + service.getKey() + "' does not exist");
     }
     masterService.setActive(service.isActive());
     masterService.setPublicService(service.isPublicService());
     this.getApiCatalogDAO().updateService(masterService);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "updateApiServiceStatus",
         "Error updating api service '" + service.getKey() + "'");
     throw new ApsSystemException("Error updating service '" + service.getKey() + "'", t);
   }
 }
 protected boolean checkServiceAuthorization(
     ApiService service, Properties properties, boolean throwApiException)
     throws ApiException, Throwable {
   if (!service.getRequiredAuth()) {
     return true;
   }
   try {
     UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
     if (null == user) {
       throw new ApiException(
           IApiErrorCodes.API_AUTHENTICATION_REQUIRED,
           "Authentication is mandatory for service '" + service.getKey() + "'",
           Response.Status.UNAUTHORIZED);
     }
     if ((null != service.getRequiredGroup()
             && !this.getAuthorizationManager().isAuthOnGroup(user, service.getRequiredGroup()))
         || (null != service.getRequiredPermission()
             && !this.getAuthorizationManager()
                 .isAuthOnPermission(user, service.getRequiredPermission()))) {
       throw new ApiException(
           IApiErrorCodes.API_AUTHORIZATION_REQUIRED,
           "Permission denied for service '" + service.getKey() + "'",
           Response.Status.UNAUTHORIZED);
     }
   } catch (ApiException ae) {
     if (throwApiException) {
       throw ae;
     }
     return false;
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "checkServiceAuthorization",
         "Error checking auth for service - key '" + service.getKey() + "'");
     throw t;
   }
   return true;
 }
 @Override
 public ApiService clone() {
   ApiService clone = new ApiService();
   clone.setDescription(this.getDescription());
   if (null != this.getFreeParameters()) {
     String[] freeParameters = new String[this.getFreeParameters().length];
     for (int i = 0; i < this.getFreeParameters().length; i++) {
       freeParameters[i] = this.getFreeParameters()[i];
     }
     clone.setFreeParameters(freeParameters);
   }
   clone.setKey(this.getKey());
   clone.setMaster(this.getMaster().clone());
   if (null != this.getParameters()) {
     clone.setParameters(this.getParameters().clone());
   }
   clone.setTag(this.getTag());
   clone.setPublicService(this.isPublicService());
   clone.setActive(this.isActive());
   clone.setMyEntando(this.isMyEntando());
   clone.setRequiredAuth(this.getRequiredAuth());
   clone.setRequiredGroup(this.getRequiredGroup());
   clone.setRequiredPermission(this.getRequiredPermission());
   return clone;
 }
 @Override
 public String edit() {
   try {
     String check = this.checkService(this.getServiceKey());
     if (null != check) return check;
     ApiService apiService = this.getApiCatalogManager().getApiService(this.getServiceKey());
     this.setApiParameters(apiService.getMaster().getParameters());
     this.setApiMethodName(apiService.getMaster().getMethodName());
     this.setApiParameterValues(apiService.getParameters());
     this.setDescriptions(apiService.getDescription());
     this.setPublicService(apiService.isPublicService());
     this.setActiveService(apiService.isActive());
     this.setMyEntandoService(apiService.isMyEntando());
     this.setServiceKey(apiService.getKey());
     if (null != apiService.getFreeParameters()) {
       List<String> freeParams = Arrays.asList(apiService.getFreeParameters());
       this.setFreeParameters(freeParams);
     }
     this.setTag(apiService.getTag());
     this.setStrutsAction(ApsAdminSystemConstants.EDIT);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "edit");
     return FAILURE;
   }
   return SUCCESS;
 }
 public void updateService(ApiService service) {
   Connection conn = null;
   PreparedStatement stat = null;
   try {
     conn = this.getConnection();
     conn.setAutoCommit(false);
     stat = conn.prepareStatement(UPDATE_SERVICE);
     // SET resource = ? , description = ? , parameters = ? , tag = ? , freeparameters = ? ,
     // isactive = ? , ispublic = ? WHERE servicekey = ? ";
     stat.setString(1, service.getMaster().getResourceName());
     stat.setString(2, service.getDescription().toXml());
     stat.setString(3, service.getParameters().toXml());
     stat.setString(4, service.getTag());
     if (null == service.getFreeParameters() || service.getFreeParameters().length == 0) {
       stat.setNull(5, Types.VARCHAR);
     } else {
       ServiceExtraConfigDOM dom = new ServiceExtraConfigDOM();
       stat.setString(5, dom.extractXml(service.getFreeParameters()));
     }
     int isActive = (service.isActive()) ? 1 : 0;
     stat.setInt(6, isActive);
     int isPublic = (service.isPublicService()) ? 1 : 0;
     stat.setInt(7, isPublic);
     int isMyEntando = (service.isMyEntando()) ? 1 : 0;
     stat.setInt(8, isMyEntando);
     stat.setString(9, service.getKey());
     stat.executeUpdate();
     conn.commit();
   } catch (Throwable t) {
     this.executeRollback(conn);
     processDaoException(t, "Error while updating a service", "updateService");
   } finally {
     closeDaoResources(null, stat, conn);
   }
 }