protected String extractTemplate(ApiMethod apiMethod) throws Exception {
   String template = null;
   InputStream is = null;
   try {
     StringBuffer path = new StringBuffer("classpath*:/api/");
     if (null != apiMethod.getPluginCode()) {
       path.append("plugins/" + apiMethod.getPluginCode() + "/");
     } else if (!apiMethod.getSource().equalsIgnoreCase("core")) {
       path.append(apiMethod.getSource() + "/");
     }
     path.append("aps/get/" + apiMethod.getResourceName() + "/description-item.vm");
     Resource[] resources =
         ApsWebApplicationUtils.getResources(path.toString(), this.getServletContext());
     if (null != resources && resources.length == 1) {
       Resource resource = resources[0];
       is = resource.getInputStream();
     }
     if (null == is) {
       ApsSystemUtils.getLogger()
           .info("Null Input Stream - template file path " + path.toString());
       return null;
     }
     template = FileTextReader.getText(is);
   } catch (Throwable t) {
     String message = "Error extracting template - " + this.buildApiSignature(apiMethod);
     ApsSystemUtils.logThrowable(t, this, "extractTemplate", message);
   } finally {
     if (null != is) {
       is.close();
     }
   }
   return template;
 }
 public ApiMethod extractApiMethod(ApiMethod.HttpMethod httpMethod, String resourceName)
     throws ApiException {
   ApiMethod api = null;
   try {
     api = this.getApiCatalogManager().getMethod(httpMethod, resourceName);
     if (null == api) {
       throw new ApiException(
           IApiErrorCodes.API_INVALID,
           this.buildApiSignature(httpMethod, resourceName) + " does not exists");
     }
     if (!api.isActive()) {
       throw new ApiException(
           IApiErrorCodes.API_ACTIVE_FALSE,
           this.buildApiSignature(httpMethod, resourceName) + " is not active");
     }
   } catch (ApiException ae) {
     ApsSystemUtils.logThrowable(
         ae,
         this,
         "extractApi",
         "Error extracting api method " + this.buildApiSignature(httpMethod, resourceName));
     throw ae;
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "extractApi",
         "Error extracting api method - " + this.buildApiSignature(httpMethod, resourceName));
     throw new ApiException(
         IApiErrorCodes.SERVER_ERROR,
         this.buildApiSignature(httpMethod, resourceName) + " is not supported");
   }
   return api;
 }
 private String extractHtmlResult(
     Object masterResult,
     AbstractApiResponse apiResponse,
     ApiMethod apiMethod,
     Properties parameters,
     Object bean) {
   String htmlResult = null;
   try {
     htmlResult = (String) this.invokeGetMethod(apiMethod, bean, "ToHtml", parameters, false);
     if (null != htmlResult) {
       return htmlResult;
     }
     String template = this.extractTemplate(apiMethod);
     if (null == template) {
       return null;
     }
     htmlResult = this.getVelocityRenderer().render(masterResult, template);
   } catch (ApiException t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "extractHtmlResult",
         "Error creating html response - " + this.buildApiSignature(apiMethod));
     if (null != t.getErrors()) {
       apiResponse.addErrors(t.getErrors());
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "extractHtmlResult",
         "Error creating html response - " + this.buildApiSignature(apiMethod));
   }
   return htmlResult;
 }
 public Map<String, ApiMethod> getRelatedShowletMethods() throws ApsSystemException {
   Map<String, ApiMethod> mapping = new HashMap<String, ApiMethod>();
   try {
     List<ApiMethod> masterMethods = this.getMasterMethods(ApiMethod.HttpMethod.GET);
     for (int i = 0; i < masterMethods.size(); i++) {
       ApiMethod apiMethod = masterMethods.get(i);
       ApiMethodRelatedShowlet relatedShowlet = apiMethod.getRelatedShowlet();
       if (null != relatedShowlet) {
         String showletCode = relatedShowlet.getShowletCode();
         if (mapping.containsKey(showletCode)) {
           ApiMethod alreadyMapped = mapping.get(showletCode);
           String alertMessage =
               "There is more than one method related whith showlet '"
                   + showletCode
                   + "' - "
                   + "Actual mapped '"
                   + alreadyMapped.getResourceName()
                   + "'; other method '"
                   + apiMethod.getResourceName()
                   + "'";
           ApsSystemUtils.getLogger().severe(alertMessage);
         } else {
           mapping.put(showletCode, apiMethod.clone());
         }
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t, this, "getRelatedShowletMethods", "Error loading related showlet methods");
     throw new ApsSystemException("Error loading related showlet methods", t);
   }
   return mapping;
 }
 @Override
 public List<Shortcut> getAllowedShortcuts(UserDetails user) throws ApsSystemException {
   List<Shortcut> allowedShortcuts = new ArrayList<Shortcut>();
   if (null == user) {
     ApsSystemUtils.getLogger().info("Required allowed shortcut for null user");
     return allowedShortcuts;
   }
   try {
     Iterator<Shortcut> shorCutIter = this.getShortcuts().values().iterator();
     while (shorCutIter.hasNext()) {
       Shortcut shortcut = shorCutIter.next();
       String permissionName = shortcut.getRequiredPermission();
       if (null == permissionName
           || this.getAuthorizationManager().isAuthOnPermission(user, permissionName)) {
         allowedShortcuts.add(shortcut.clone());
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "getAllowedShortcuts");
     throw new ApsSystemException(
         "Error extracting allowed shortcuts by user " + user.getUsername(), t);
   }
   BeanComparator comparator = new BeanComparator("source");
   Collections.sort(allowedShortcuts, comparator);
   return allowedShortcuts;
 }
 /**
  * Verify the validity of the Authority.
  *
  * @param authority The authority to verify.
  * @return True if the authority is valid, else false.
  */
 protected boolean checkAuthority(IApsAuthority authority) {
   if (null == authority) {
     ApsSystemUtils.getLogger().severe("Invalid authority detected");
     //					"Required Users by null authority";
     return false;
   }
   IApsAuthority authForCheck = this.getAuthority(authority.getAuthority());
   if (null == authForCheck) {
     ApsSystemUtils.getLogger()
         .severe("The authority with code " + authority.getAuthority() + " does not exist");
     //					"Required Users by not existing authority : code " + authority.getAuthority());
     return false;
   }
   if (!authForCheck.getClass().equals(authority.getClass())) {
     ApsSystemUtils.getLogger()
         .severe(
             "Mismatching authority classes detected; code "
                 + authority.getAuthority()
                 + " - Class "
                 + authority.getClass()
                 + " is different by "
                 + authForCheck.getClass());
     //					"Required Users by invalid authority: code " + authority.getAuthority() + " - Class " +
     // authority.getClass());
     return false;
   }
   return true;
 }
 /**
  * Invia i contenuti dati agli utenti registrati alla newsletter discriminando, per ogni utente, i
  * contenuti a lui visibili e per i quali ha fatto implicita richiesta nel proprio profilo.
  *
  * @param contents La lista dei contenuti da inviare tramite newsletter.
  * @throws ApsSystemException In caso di errore.
  */
 protected void sendNewsletterToUsers(List<Content> contents) throws ApsSystemException {
   try {
     Map<String, List<String>> profileAttributes =
         this.prepareProfileAttributesForContents(contents);
     NewsletterReport newsletterReport = this.prepareNewsletterReport(contents);
     Set<String> usernames = this.extractUsernames();
     if (null != usernames && usernames.size() > 0) {
       Iterator<String> userIter = usernames.iterator();
       while (userIter.hasNext()) {
         String username = (String) userIter.next();
         UserDetails user = this.getUserManager().getUser(username);
         if (null != user && !user.isDisabled()) {
           this.sendNewsletterToUser(username, contents, profileAttributes, newsletterReport);
         }
       }
     } else {
       ApsSystemUtils.getLogger().severe("Newsletter: no receivers to send newsletter to!");
     }
     this.sendNewsletterToSubscribers(contents, newsletterReport);
     this.addNewsletterReport(newsletterReport);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "sendNewsletterToUsers");
     throw new ApsSystemException("Error sending Newsletter To Users ", t);
   }
 }
 protected IDatabaseManager.DatabaseType getType(DataSource dataSource) throws ApsSystemException {
   String typeString = null;
   try {
     String driverClassName = this.invokeGetMethod("getDriverClassName", dataSource);
     Iterator<Object> typesIter = this.getDatabaseTypeDrivers().keySet().iterator();
     while (typesIter.hasNext()) {
       String typeCode = (String) typesIter.next();
       List<String> driverClassNames = (List<String>) this.getDatabaseTypeDrivers().get(typeCode);
       if (null != driverClassNames && driverClassNames.contains(driverClassName)) {
         typeString = typeCode;
         break;
       }
     }
     if (null == typeString) {
       ApsSystemUtils.getLogger()
           .severe(
               "Type not recognized for Driver '"
                   + driverClassName
                   + "' - "
                   + "Recognized types '"
                   + IDatabaseManager.DatabaseType.values()
                   + "'");
       return IDatabaseManager.DatabaseType.UNKNOWN;
     }
     return Enum.valueOf(IDatabaseManager.DatabaseType.class, typeString.toUpperCase());
   } catch (Throwable t) {
     ApsSystemUtils.getLogger()
         .severe("Invalid type for db - '" + typeString + "' - " + t.getMessage());
     throw new ApsSystemException("Invalid type for db - '" + typeString + "'", t);
   }
 }
 protected Object invokeGetMethod(
     ApiMethod apiMethod,
     Object bean,
     String methodSuffix,
     Properties parameters,
     boolean throwException)
     throws ApiException, Throwable {
   String methodName = null;
   Object result = null;
   try {
     Class[] parameterTypes = new Class[] {Properties.class};
     Class beanClass = bean.getClass();
     methodName =
         (null != methodSuffix)
             ? apiMethod.getSpringBeanMethod() + methodSuffix.trim()
             : apiMethod.getSpringBeanMethod();
     Method method = beanClass.getDeclaredMethod(methodName, parameterTypes);
     result = method.invoke(bean, parameters);
   } catch (NoSuchMethodException e) {
     if (throwException) {
       ApsSystemUtils.logThrowable(
           e,
           this,
           "invokeGetMethod",
           "No such method '" + methodName + "' of class '" + bean.getClass() + "'");
       throw new ApiException(
           IApiErrorCodes.API_METHOD_ERROR,
           "Method not supported - " + this.buildApiSignature(apiMethod));
     }
   } catch (InvocationTargetException e) {
     if (e.getTargetException() instanceof ApiException) {
       throw (ApiException) e.getTargetException();
     } else if (throwException) {
       ApsSystemUtils.logThrowable(
           e.getTargetException(),
           this,
           "invokeGetMethod",
           "Error invoking method '" + methodName + "' of class '" + bean.getClass() + "'");
       throw new ApiException(
           IApiErrorCodes.API_METHOD_ERROR,
           "Error invoking Method - " + this.buildApiSignature(apiMethod));
     }
   } catch (Throwable t) {
     if (throwException) {
       ApsSystemUtils.logThrowable(
           t,
           this,
           "invokeGetMethod",
           "Error invoking method - "
               + this.buildApiSignature(apiMethod)
               + methodName
               + "' of class '"
               + bean.getClass()
               + "'");
       throw t;
     }
   }
   return result;
 }
 protected Object invokePutPostDeleteMethod(
     ApiMethod apiMethod, Object bean, Properties parameters, Object bodyObject)
     throws ApiException, Throwable {
   Object result = null;
   try {
     if (apiMethod.getHttpMethod().equals(ApiMethod.HttpMethod.DELETE)) {
       result = this.invokeDeleteMethod(apiMethod, bean, parameters);
     } else {
       result = this.invokePutPostMethod(apiMethod, bean, parameters, bodyObject);
     }
     if (null != result) return result;
     BaseApiResponse response = new BaseApiResponse();
     response.setResult(SUCCESS, null);
     result = response;
   } catch (NoSuchMethodException e) {
     ApsSystemUtils.logThrowable(
         e,
         this,
         "invokePutPostDeleteMethod",
         "No such method '"
             + apiMethod.getSpringBeanMethod()
             + "' of class '"
             + bean.getClass()
             + "'");
     throw new ApiException(
         IApiErrorCodes.API_METHOD_ERROR,
         "Method not supported - " + this.buildApiSignature(apiMethod));
   } catch (InvocationTargetException e) {
     if (e.getTargetException() instanceof ApiException) {
       throw (ApiException) e.getTargetException();
     } else {
       ApsSystemUtils.logThrowable(
           e.getTargetException(),
           this,
           "invokePutPostDeleteMethod",
           "Error invoking method '"
               + apiMethod.getSpringBeanMethod()
               + "' of class '"
               + bean.getClass()
               + "'");
       throw new ApiException(
           IApiErrorCodes.API_METHOD_ERROR,
           "Error invoking Method - " + this.buildApiSignature(apiMethod));
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "invokePutPostDeleteMethod",
         "Error invoking method '"
             + apiMethod.getSpringBeanMethod()
             + "' of class '"
             + bean.getClass()
             + "'");
     throw t;
   }
   return result;
 }
 protected boolean checkNode(String nodeCode, Collection<String> groupCodes) {
   if (!this.isNodeAllowed(nodeCode, groupCodes)) {
     ApsSystemUtils.getLogger().severe("Node '" + nodeCode + "' not allowed ");
     return false;
   }
   ITreeNode treeNode = this.getTreeNode(nodeCode);
   if (null == treeNode) {
     ApsSystemUtils.getLogger().severe("Node '" + nodeCode + "' null ");
     return false;
   }
   return true;
 }
 protected void loadResources() throws ApsSystemException {
   try {
     ApiResourceLoader loader =
         new ApiResourceLoader(this.getLocationPatterns(), this.getServletContext());
     Map<String, ApiResource> resources = loader.getResources();
     this.setMasterResources(resources);
     ApsSystemUtils.getLogger().config(this.getClass().getName() + ": initialized Api Methods");
     this.getApiCatalogDAO().loadApiStatus(resources);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t, this, "loadResources", "Error loading Api Resources definitions");
     throw new ApsSystemException("Error loading Api Resources definitions", t);
   }
 }
 private String prepareSubscribersMailBody(
     List<Content> userContents,
     NewsletterReport newsletterReport,
     boolean isHtml,
     String mailAddress) {
   NewsletterConfig config = this.getConfig();
   String unsubscriptionLink =
       isHtml ? config.getSubscribersHtmlFooter() : config.getSubscribersTextFooter();
   if (unsubscriptionLink != null) {
     StringBuffer body = this.prepareMailCommonBody(userContents, newsletterReport, isHtml);
     String link = this.createUnsubscriptionLink(mailAddress);
     Map<String, String> footerParams = new HashMap<String, String>();
     footerParams.put("unsubscribeLink", link);
     String unlink = this.parseText(unsubscriptionLink, footerParams);
     body.append(unlink);
     return body.toString();
   } else {
     ApsSystemUtils.getLogger()
         .warning(
             "Incomplete configuration for newsletter subscribers! CHECK "
                 + JpnewsletterSystemConstants.NEWSLETTER_CONFIG_ITEM
                 + " item!!");
     return this.prepareMailBody(userContents, newsletterReport, isHtml);
   }
 }
 protected String saveOperation(int operationCode) {
   try {
     String code = this.getCode();
     ITicketManager ticketManager = this.getTicketManager();
     Ticket ticket = ticketManager.getTicket(code);
     if (ticket != null) {
       this.setTicket(ticket);
       boolean allowed = this.isOperationAllowed(ticket, operationCode);
       boolean validated = this.validateParameters(ticket, operationCode, allowed);
       if (!allowed) {
         return "opNotAllowed";
       } else if (!validated) {
         return INPUT;
       } else {
         Ticket newTicket = this.createTicketForUpdate(ticket, operationCode);
         TicketOperation operation = this.createTicketOperation(operationCode);
         ticketManager.updateTicketWithOperation(newTicket, operation);
         this.addActionMessage(this.getText("Message.ticketOperation.completed"));
       }
     } else {
       this.addActionError(this.getText("Errors.ticketOperation.ticketNotFound"));
       return "ticketNotFound";
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "view");
     return FAILURE;
   }
   return SUCCESS;
 }
 private void checkParameters() {
   try {
     this.setApiParameterValues(new ApsProperties());
     ApiMethod masterMethod = this.getMethod(this.getApiMethodName());
     List<ApiMethodParameter> apiParameters = masterMethod.getParameters();
     this.setApiParameters(apiParameters);
     for (int i = 0; i < apiParameters.size(); i++) {
       ApiMethodParameter apiParameter = apiParameters.get(i);
       String fieldName = apiParameter.getKey() + "_apiParam";
       String value = this.getRequest().getParameter(fieldName);
       if (null != value && value.trim().length() > 0) {
         this.getApiParameterValues().put(apiParameter.getKey(), value);
       }
       boolean isFreeParameter =
           (null != this.getFreeParameters())
               ? this.getFreeParameters().contains(apiParameter.getKey())
               : false;
       if (apiParameter.isRequired()
           && (null == value || value.trim().length() == 0)
           && !isFreeParameter) {
         this.addFieldError(
             fieldName,
             this.getText(
                 "error.service.parameter.invalidSetting",
                 new String[] {apiParameter.getKey(), apiParameter.getDescription()}));
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "checkParameters");
     throw new RuntimeException("Error checking parameters", t);
   }
 }
 @Override
 public String save() {
   try {
     String key = this.getServiceKey().trim();
     ApiMethod masterMethod = this.getMethod(this.getApiMethodName());
     String[] freeParams = null;
     if (null != this.getFreeParameters()) {
       freeParams = new String[this.getFreeParameters().size()];
       for (int i = 0; i < this.getFreeParameters().size(); i++) {
         freeParams[i] = this.getFreeParameters().get(i);
       }
     }
     ApiService service =
         new ApiService(
             key,
             this.getDescriptions(),
             masterMethod,
             this.getApiParameterValues(),
             freeParams,
             this.getTag(),
             this.isPublicService(),
             this.isActiveService(),
             this.isMyEntandoService());
     this.getApiCatalogManager().saveService(service);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "save");
     return FAILURE;
   }
   return SUCCESS;
 }
 @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;
 }
 /**
  * Verifica che l'utente in sessione sia abilitato all'accesso alla pagina richiesta. Se è
  * autorizzato il metodo termina con CONTINUE, altrimenti con REDIRECT impostando prima i
  * parametri di redirezione alla pagina di login.
  *
  * @param reqCtx Il contesto di richiesta
  * @param status Lo stato di uscita del servizio precedente
  * @return Lo stato di uscita
  */
 @Override
 public int service(RequestContext reqCtx, int status) {
   if (_log.isLoggable(Level.FINEST)) {
     _log.finest("Invoked: " + this.getClass().getName());
   }
   int retStatus = ControllerManager.INVALID_STATUS;
   if (status == ControllerManager.ERROR) {
     return status;
   }
   try {
     HttpServletRequest req = reqCtx.getRequest();
     HttpSession session = req.getSession();
     IPage currentPage = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
     UserDetails currentUser =
         (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
     if (null == currentUser) {
       throw new ApsSystemException("no user on session");
     }
     boolean authorized = this.getAuthManager().isAuth(currentUser, currentPage);
     if (authorized) {
       retStatus = ControllerManager.CONTINUE;
     } else {
       retStatus = this.redirect(this.getLoginPageCode(), reqCtx);
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "service", "Error while processing the request");
     retStatus = ControllerManager.SYS_ERROR;
     reqCtx.setHTTPError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
   }
   return retStatus;
 }
 @Override
 public int doStartTag() throws JspException {
   try {
     Widget widget = this.extractShowlet();
     if (null == widget) return super.doStartTag();
     String value = null;
     if ("code".equals(this.getParam())) {
       value = widget.getType().getCode();
     } else if ("title".equals(this.getParam())) {
       value = this.extractTitle(widget);
     } else if ("config".equals(this.getParam())) {
       ApsProperties config = widget.getConfig();
       if (null != config) {
         value = config.getProperty(this.getConfigParam());
       }
     }
     if (null != value) {
       String var = this.getVar();
       if (null == var || "".equals(var)) {
         if (this.getEscapeXml()) {
           out(this.pageContext, this.getEscapeXml(), value);
         } else {
           this.pageContext.getOut().print(value);
         }
       } else {
         this.pageContext.setAttribute(this.getVar(), value);
       }
     }
   } catch (Throwable t) {
     String msg = "Error detected during showlet preprocessing";
     ApsSystemUtils.logThrowable(t, this, "doEndTag", msg);
     throw new JspException(msg, t);
   }
   return super.doStartTag();
 }
 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;
 }
 @Override
 public String edit() {
   try {
     IContact contact = this.getAddressBookManager().getContact(this.getEntityId());
     if (null == contact) {
       this.addFieldError(
           "contactKey", this.getText("*CONTATTO NULLO*")); // TODO LABEL DA MODIFICARE
       return INPUT;
     }
     if (!contact.isPublicContact()
         && !this.getCurrentUser().getUsername().equals(contact.getOwner())) {
       this.addFieldError(
           "contactKey",
           this.getText("*CONTATTO NON PUBBLICO NON AUTORIZZATO*")); // TODO LABEL DA MODIFICARE
       return INPUT;
     }
     contact
         .getContactInfo()
         .disableAttributes(
             JpaddressbookSystemConstants.ATTRIBUTE_DISABLING_CODE_ON_MANAGE_CONTACT);
     this.getRequest().getSession().setAttribute(SESSION_PARAM_NAME_CURRENT_CONTACT, contact);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "edit");
     return FAILURE;
   }
   return SUCCESS;
 }
 public JAXBResource getResource(Properties properties) throws Throwable {
   JAXBResource jaxbResource = null;
   String id = properties.getProperty("id");
   String resourceTypeCode = properties.getProperty(RESOURCE_TYPE_CODE_PARAM);
   try {
     ResourceInterface resource = this.getResourceManager().loadResource(id);
     if (null == resource || !resource.getType().equalsIgnoreCase(resourceTypeCode)) {
       throw new ApiException(
           IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR,
           "Null resource by id '" + id + "'",
           Response.Status.CONFLICT);
     }
     UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
     if (null == user) {
       user = this.getUserManager().getGuestUser();
     }
     String groupName = resource.getMainGroup();
     if (!Group.FREE_GROUP_NAME.equals(groupName)
         && !this.getAuthorizationManager().isAuthOnGroup(user, groupName)) {
       throw new ApiException(
           IApiErrorCodes.API_VALIDATION_ERROR,
           "Required resource '" + id + "' does not allowed",
           Response.Status.FORBIDDEN);
     }
     jaxbResource = new JAXBResource(resource);
   } catch (ApiException ae) {
     throw ae;
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "getResource");
     throw new ApsSystemException("Error into API method", t);
   }
   return jaxbResource;
 }
 protected void initItems() {
   if (null != this.getStaticItems() && this.getStaticItems().trim().length() > 0) {
     this.setItems(this.getStaticItems().split(this.getCustomSeparator()));
   }
   if (null != this.getExtractorBeanName()) {
     try {
       EnumeratorAttributeItemsExtractor extractor =
           (EnumeratorAttributeItemsExtractor)
               this.getBeanFactory()
                   .getBean(this.getExtractorBeanName(), EnumeratorAttributeItemsExtractor.class);
       if (null != extractor) {
         List<String> items = extractor.getItems();
         if (items != null && items.size() > 0) this.addExtractedItems(items);
       }
     } catch (Throwable t) {
       ApsSystemUtils.logThrowable(
           t,
           this,
           "initItems",
           "Error while extract items from bean extractor '" + this.getExtractorBeanName() + "'");
     }
   }
   if (null != this.getItems()) {
     String[] items = new String[this.getItems().length];
     for (int i = 0; i < this.getItems().length; i++) {
       if (null != this.getItems()[i]) {
         items[i] = this.getItems()[i].trim();
       }
     }
     this.setItems(items);
   }
 }
 public IApsEntity buildEntityType(Class entityClass, Map<String, AttributeInterface> attributes)
     throws ApiException, Throwable {
   List<ApiError> errors = new ArrayList<ApiError>();
   IApsEntity entityType = null;
   try {
     entityType = (IApsEntity) entityClass.newInstance();
     entityType.setTypeCode(this.getTypeCode());
     entityType.setTypeDescr(this.getTypeDescription());
     List<DefaultJAXBAttributeType> jabxAttributes = this.getAttributes();
     for (int i = 0; i < jabxAttributes.size(); i++) {
       try {
         DefaultJAXBAttributeType jaxbAttributeType = jabxAttributes.get(i);
         AttributeInterface attribute = jaxbAttributeType.createAttribute(attributes);
         if (null != entityType.getAttribute(attribute.getName())) {
           throw new ApiException(
               IApiErrorCodes.API_VALIDATION_ERROR,
               "Attribute '" + attribute.getName() + "' already defined");
         }
         entityType.addAttribute(attribute);
       } catch (ApiException e) {
         errors.addAll(e.getErrors());
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "buildEntityType");
     throw t;
   }
   if (!errors.isEmpty()) throw new ApiException(errors);
   return entityType;
 }
 protected NewsletterReport prepareNewsletterReport(List<Content> contents) {
   NewsletterConfig config = this.getConfig();
   NewsletterReport newsletterReport = new NewsletterReport();
   newsletterReport.setSubject(config.getSubject());
   newsletterReport.setSendDate(new Date());
   String defaultLang = this.getLangManager().getDefaultLang().getCode();
   boolean alsoHtml = config.isAlsoHtml();
   for (Content content : contents) {
     boolean isConfiguredWithModels = false;
     ContentReport contentReport = new ContentReport();
     contentReport.setContentId(content.getId());
     String textBodyPart = this.prepareMailBodyContentPart(content, defaultLang, false);
     if (null != textBodyPart) {
       isConfiguredWithModels = true;
       contentReport.setTextBody(textBodyPart);
     }
     if (alsoHtml) {
       String htmlBodyPart = this.prepareMailBodyContentPart(content, defaultLang, true);
       contentReport.setHtmlBody(htmlBodyPart);
     }
     if (isConfiguredWithModels) {
       newsletterReport.addContentReport(contentReport);
     } else {
       ApsSystemUtils.getLogger()
           .info(
               " Newsletter content "
                   + content.getId()
                   + " not added, because has not model in config.");
     }
   }
   return newsletterReport;
 }
 private boolean isDuplicateFile(
     JAXBResource jaxbResource, ResourceInterface resourcePrototype, boolean add) {
   if (null == jaxbResource.getBase64()) return false;
   boolean addError = true;
   String formFileName = jaxbResource.getFileName();
   try {
     resourcePrototype.setMainGroup(jaxbResource.getMainGroup());
     if (resourcePrototype.exists(formFileName)) {
       if (!add) {
         ResourceInterface masterResource =
             this.getResourceManager().loadResource(jaxbResource.getId());
         String masterFileName =
             (null != masterResource) ? masterResource.getMasterFileName() : null;
         if (null != masterFileName && masterFileName.equalsIgnoreCase(formFileName)) {
           addError = false;
         }
       }
     } else {
       addError = false;
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "isDuplicateFile",
         "Error while check duplicate file - master file name '" + formFileName + "'");
   }
   return addError;
 }
 @Override
 public List<AttributeFieldError> validate(AttributeTracer tracer) {
   List<AttributeFieldError> errors = new ArrayList<AttributeFieldError>();
   try {
     if (this.getStatus().equals(Status.INCOMPLETE)) {
       errors.add(new AttributeFieldError(this, FieldError.INVALID, tracer));
     } else {
       IAttributeValidationRules validationRules = this.getValidationRules();
       if (null == validationRules) {
         return errors;
       }
       ILangManager langManager =
           (ILangManager)
               this.getBeanFactory().getBean(SystemConstants.LANGUAGE_MANAGER, ILangManager.class);
       List<AttributeFieldError> validationRulesErrors =
           validationRules.validate(this, tracer, langManager);
       if (null != validationRulesErrors) {
         errors.addAll(validationRulesErrors);
       }
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t, this, "validate", "Error validating Attribute '" + this.getName() + "'");
     throw new RuntimeException("Error validating Attribute '" + this.getName() + "'", t);
   }
   return errors;
 }
 public void updateMethodConfig(ApiMethod apiMethod) throws ApsSystemException {
   try {
     ApiMethod masterMethod = this.checkMethod(apiMethod);
     this.getApiCatalogDAO().saveApiStatus(apiMethod);
     masterMethod.setStatus(apiMethod.getStatus());
     masterMethod.setRequiredAuth(apiMethod.getRequiredAuth());
     String requiredPermission = apiMethod.getRequiredPermission();
     if (null != requiredPermission && requiredPermission.trim().length() > 0) {
       masterMethod.setRequiredPermission(requiredPermission);
     } else {
       masterMethod.setRequiredPermission(null);
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(
         t,
         this,
         "updateMethodConfig",
         "Error error updating api status : "
             + "resource '"
             + apiMethod.getResourceName()
             + "' method '"
             + apiMethod.getHttpMethod()
             + "' ");
     throw new ApsSystemException("Error updating api status", t);
   }
 }
 /**
  * Imposta i parametri di una redirezione.
  *
  * @param redirDestPage Il codice della pagina su cui si vuole redirezionare.
  * @param reqCtx Il contesto di richiesta.
  * @return L'indicativo del tipo di redirezione in uscita del controlService. Può essere una delle
  *     costanti definite in ControllerManager.
  */
 protected int redirect(String redirDestPage, RequestContext reqCtx) {
   int retStatus;
   try {
     String redirPar = this.getParameter(RequestContext.PAR_REDIRECT_FLAG, reqCtx);
     if (redirPar == null || "".equals(redirPar)) {
       PageURL url = this.getUrlManager().createURL(reqCtx);
       url.setPageCode(redirDestPage);
       url.addParam(RequestContext.PAR_REDIRECT_FLAG, "1");
       String redirUrl = url.getURL();
       if (_log.isLoggable(Level.FINEST)) {
         _log.finest("Redirecting to " + redirUrl);
       }
       reqCtx.clearError();
       reqCtx.addExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL, redirUrl);
       retStatus = ControllerManager.REDIRECT;
     } else {
       reqCtx.setHTTPError(HttpServletResponse.SC_BAD_REQUEST);
       retStatus = ControllerManager.ERROR;
     }
   } catch (Throwable t) {
     retStatus = ControllerManager.SYS_ERROR;
     reqCtx.setHTTPError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
     ApsSystemUtils.logThrowable(
         t, this, "redirect", "Error on creation redirect to page " + redirDestPage);
   }
   return retStatus;
 }
 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;
 }