public String getInputType() {
   if (pathArgumentList.size() > 0) {
     Object argument = pathArgumentList.get(0);
     if (argument != null && argument instanceof SynapseXPath) {
       return XML_TYPE;
     } else if (argument != null && argument instanceof SynapseJsonPath) {
       return JSON_TYPE;
     }
   }
   return null;
 }
 /**
  * Goes through SynapsePath argument list, evaluating each by calling stringValueOf and returns a
  * HashMap String, String array where each item will contain a hash map with key "evaluated
  * expression" and value "SynapsePath type".
  *
  * @param synCtx
  * @return
  */
 private HashMap<String, String>[] getArgValues(MessageContext synCtx) {
   HashMap<String, String>[] argValues = new HashMap[pathArgumentList.size()];
   HashMap<String, String> valueMap;
   String value = "";
   for (int i = 0; i < pathArgumentList.size(); ++i) {
       /*ToDo use foreach*/
     Argument arg = pathArgumentList.get(i);
     if (arg.getValue() != null) {
       value = arg.getValue();
       if (!isWellFormedXML(value)) {
         value = StringEscapeUtils.escapeXml(value);
       }
       value = Matcher.quoteReplacement(value);
     } else if (arg.getExpression() != null) {
       value = arg.getExpression().stringValueOf(synCtx);
       if (value != null) {
         // XML escape the result of an expression that produces a literal, if the target format
         // of the payload is XML.
         if (!isWellFormedXML(value)
             && !arg.getExpression().getPathType().equals(SynapsePath.JSON_PATH)
             && XML_TYPE.equals(getType())) {
           value = StringEscapeUtils.escapeXml(value);
         }
         value = Matcher.quoteReplacement(value);
       } else {
         value = "";
       }
     } else {
       handleException("Unexpected arg type detected", synCtx);
     }
     // value = value.replace(String.valueOf((char) 160), " ").trim();
     valueMap = new HashMap<String, String>();
     if (null != arg.getExpression()) {
       valueMap.put(value, arg.getExpression().getPathType());
     } else {
       valueMap.put(value, SynapsePath.X_PATH);
     }
     argValues[i] = valueMap;
   }
   return argValues;
 }
예제 #3
0
 public static SimulationResponse getSimulationResponse() {
   Map<String, List<String[]>> status = simulationService.getSimulationStatus();
   int entryCount = 0;
   Map<Integer, HandlerExecutionStatus> executionStatusMap =
       new HashMap<Integer, HandlerExecutionStatus>();
   if (status != null) {
     for (Map.Entry<String, List<String[]>> e : status.entrySet()) {
       if (e.getKey() != null && e.getValue() != null) {
         if (e.getValue().size() > 0) {
           for (String[] v : e.getValue()) {
             if (v != null && v.length == 2) {
               HandlerExecutionStatus executionStatus = new HandlerExecutionStatus();
               executionStatus.setHandlerName(e.getKey());
               executionStatus.setExecutionStatus(v[0]);
               int order = Integer.parseInt(v[1]);
               executionStatusMap.put(order, executionStatus);
               if (order > entryCount) {
                 entryCount = order;
               }
             }
           }
         }
       }
     }
   }
   List<HandlerExecutionStatus> executionStatusList = new LinkedList<HandlerExecutionStatus>();
   int i = 0;
   while (i < entryCount) {
     i++;
     HandlerExecutionStatus executionStatus = executionStatusMap.get(i);
     if (executionStatus != null) {
       executionStatusList.add(executionStatus);
     }
   }
   SimulationResponse response = new SimulationResponse();
   response.setStatus(
       executionStatusList.toArray(new HandlerExecutionStatus[executionStatusList.size()]));
   return response;
 }
예제 #4
0
 public static void buildMenuItems(HttpServletRequest request, String s, String s1, String s2) {
   int menuOrder = 50;
   if (CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/resources/ws-api")) {
     HttpSession session = request.getSession();
     String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
     try {
       WSRegistryServiceClient registry = new WSRegistryServiceClient(s2, cookie);
       List<GovernanceArtifactConfiguration> configurations =
           GovernanceUtils.findGovernanceArtifactConfigurations(registry);
       Map<String, String> customAddUIMap = new LinkedHashMap<String, String>();
       Map<String, String> customViewUIMap = new LinkedHashMap<String, String>();
       List<Menu> userCustomMenuItemsList = new LinkedList<Menu>();
       for (GovernanceArtifactConfiguration configuration : configurations) {
         Component component = new Component();
         OMElement uiConfigurations = configuration.getUIConfigurations();
         String key = configuration.getKey();
         String configurationPath =
             RegistryConstants.CONFIG_REGISTRY_BASE_PATH
                 + RegistryConstants.GOVERNANCE_COMPONENT_PATH
                 + "/configuration/";
         String layoutStoragePath = configurationPath + key;
         RealmService realmService = registry.getRegistryContext().getRealmService();
         if (realmService
                 .getTenantUserRealm(realmService.getTenantManager().getTenantId(s1))
                 .getAuthorizationManager()
                 .isUserAuthorized(s, configurationPath, ActionConstants.PUT)
             || registry.resourceExists(layoutStoragePath)) {
           List<Menu> menuList = component.getMenusList();
           if (uiConfigurations != null) {
             ComponentBuilder.processMenus("artifactType", uiConfigurations, component);
             ComponentBuilder.processCustomUIs(uiConfigurations, component);
           }
           if (menuList.size() == 0) {
             // if no menu definitions were present, define the default ones.
             menuOrder = buildMenuList(request, configuration, menuList, key, menuOrder);
           }
           userCustomMenuItemsList.addAll(menuList);
           customAddUIMap.putAll(component.getCustomAddUIMap());
           Map<String, String> viewUIMap = component.getCustomViewUIMap();
           if (viewUIMap.isEmpty()) {
             // if no custom UI definitions were present, define the default.
             buildViewUI(configuration, viewUIMap, key);
           }
           customViewUIMap.putAll(viewUIMap);
           OMElement layout = configuration.getContentDefinition();
           if (layout != null && !registry.resourceExists(layoutStoragePath)) {
             Resource resource = registry.newResource();
             resource.setContent(RegistryUtils.encodeString(layout.toString()));
             resource.setMediaType("application/xml");
             registry.put(layoutStoragePath, resource);
           }
         }
       }
       session.setAttribute(
           MenuAdminClient.USER_CUSTOM_MENU_ITEMS,
           userCustomMenuItemsList.toArray(new Menu[userCustomMenuItemsList.size()]));
       session.setAttribute("customAddUI", customAddUIMap);
       session.setAttribute("customViewUI", customViewUIMap);
     } catch (RegistryException e) {
       log.error("unable to create connection to registry");
     } catch (org.wso2.carbon.user.api.UserStoreException e) {
       log.error("unable to realm service");
     }
   }
 }
예제 #5
0
  /*
  * This method is used to capture the lifecycle attribute from the configuration.
  *
  * expected configuration elements are
  *
  * <field type="options">
          <name label="Lifecycle Name" >Lifecycle Name</name>
          <values class="org.wso2.carbon.governance.generic.ui.utils.LifecycleListPopulator"/>
      </field>
  *
  * or
  *
  *  <field type="options">
          <name label="Lifecycle Name" >Lifecycle Name</name>
          <values class="com.foo.bar.LifecycleListPopulator" isLifecycle="true"/>
      </field>
  *  */
  private static String BuilLifecycleAttribute(
      GovernanceArtifactConfiguration configuration,
      String defaultLifecycleGeneratorClass,
      String lifecycleAttribute) {
    try {
      //            This part checks whether the user has given a lifecycle populates.
      //            If not, then we check whether there is an attribute called, "isLifecycle"
      //            This attribute will identify the lifecycle attribute from the configuration.
      OMElement configurationElement = configuration.getContentDefinition();
      String xpathExpression = "//@class";

      AXIOMXPath xpath = new AXIOMXPath(xpathExpression);
      List resultNodes = xpath.selectNodes(configurationElement);

      if (resultNodes != null && resultNodes.size() > 0) {
        String lifecycleParentName = null;
        String lifecycleName = null;

        for (Object resultNode : resultNodes) {
          OMElement parentElement = ((OMAttribute) resultNode).getOwner();
          if (parentElement
              .getAttributeValue(new QName("class"))
              .equals(defaultLifecycleGeneratorClass)) {
            Iterator childrenIterator = parentElement.getParent().getChildrenWithLocalName("name");
            while (childrenIterator.hasNext()) {
              OMElement next = (OMElement) childrenIterator.next();
              lifecycleName = next.getAttributeValue(new QName("label"));
            }
            OMElement rootElement = (OMElement) ((OMElement) parentElement.getParent()).getParent();
            lifecycleParentName = rootElement.getAttributeValue(new QName("name"));
            break;
          } else if (parentElement.getAttributeValue(new QName("isLifecycle")) != null
              && parentElement.getAttributeValue(new QName("isLifecycle")).equals("true")) {
            Iterator childrenIterator = parentElement.getParent().getChildrenWithLocalName("name");
            while (childrenIterator.hasNext()) {
              OMElement next = (OMElement) childrenIterator.next();
              lifecycleName = next.getAttributeValue(new QName("label"));
            }
            OMElement rootElement = (OMElement) ((OMElement) parentElement.getParent()).getParent();
            lifecycleParentName = rootElement.getAttributeValue(new QName("name"));
            break;
          }
        }
        if (lifecycleParentName != null && lifecycleName != null) {
          return convertName(lifecycleParentName.split(" "))
              + "_"
              + convertName(lifecycleName.split(" "));
        }
      }

    } catch (OMException e) {
      log.error(
          "Governance artifact configuration of configuration key:"
              + configuration.getKey()
              + " is invalid",
          e);
    } catch (JaxenException e) {
      log.error("Error in getting the lifecycle attribute", e);
    }
    return null;
  }