/**
   * @param clusterId
   * @param hostName
   */
  @Transactional
  public void removeHost(final long clusterId, String hostName) {

    populateCache();

    Set<HostConfigMapping> set = hostConfigMappingByHost.get(hostName);

    // Remove from cache items with clusterId
    CollectionUtils.filter(
        set,
        new Predicate() {

          @Override
          public boolean evaluate(Object arg0) {
            return !((HostConfigMapping) arg0).getClusterId().equals(clusterId);
          }
        });

    // delete from db
    TypedQuery<HostConfigMappingEntity> query =
        entityManagerProvider
            .get()
            .createQuery(
                "SELECT entity FROM HostConfigMappingEntity entity "
                    + "WHERE entity.clusterId = ?1 AND entity.hostName = ?2",
                HostConfigMappingEntity.class);

    List<HostConfigMappingEntity> list =
        daoUtils.selectList(query, Long.valueOf(clusterId), hostName);

    for (HostConfigMappingEntity entity : list) {
      entityManagerProvider.get().remove(entity);
    }
  }
  @RequiresSession
  public Set<HostConfigMapping> findSelectedByHosts(long clusterId, Collection<String> hostNames) {

    populateCache();

    if (hostNames == null || hostNames.isEmpty()) {
      return Collections.emptySet();
    }

    HashSet<HostConfigMapping> result = new HashSet<HostConfigMapping>();

    for (final String hostName : hostNames) {

      if (!hostConfigMappingByHost.containsKey(hostName)) continue;

      Set<HostConfigMapping> set =
          new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostName));

      CollectionUtils.filter(
          set,
          new Predicate() {

            @Override
            public boolean evaluate(Object arg0) {
              return ((HostConfigMapping) arg0).getHostName().equals(hostName)
                  && ((HostConfigMapping) arg0).getSelected() > 0;
            }
          });

      result.addAll(set);
    }

    return result;
  }
  @RequiresSession
  public Set<HostConfigMapping> findByType(
      final long clusterId, String hostName, final String type) {

    populateCache();

    if (!hostConfigMappingByHost.containsKey(hostName)) return Collections.emptySet();

    Set<HostConfigMapping> set =
        new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostName));

    CollectionUtils.filter(
        set,
        new Predicate() {

          @Override
          public boolean evaluate(Object arg0) {

            return ((HostConfigMapping) arg0).getClusterId().equals(clusterId)
                && ((HostConfigMapping) arg0).getType().equals(type);
          }
        });

    return set;
  }
  @Override
  public AtlasStructDefs search(SearchFilter filter) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
      LOG.debug("==> AtlasStructDefStoreV1.search({})", filter);
    }

    List<AtlasStructDef> structDefs = new ArrayList<>();
    Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.STRUCT);

    while (vertices.hasNext()) {
      AtlasVertex vertex = vertices.next();
      AtlasStructDef structDef = toStructDef(vertex);

      if (structDef != null) {
        structDefs.add(structDef);
      }
    }

    CollectionUtils.filter(structDefs, FilterUtil.getPredicateFromSearchFilter(filter));

    AtlasStructDefs ret = new AtlasStructDefs(structDefs);

    if (LOG.isDebugEnabled()) {
      LOG.debug("<== AtlasStructDefStoreV1.search({}): {}", filter, ret);
    }

    return ret;
  }
 /** As per enhancement added new group b2bviewergroup */
 public void populateRolesByCustomer(final String uuid, final CustomerData target) {
   final List<String> roles = new ArrayList<String>();
   final EnergizerB2BCustomerModel model =
       userService.getUserForUID(uuid, EnergizerB2BCustomerModel.class);
   final Set<PrincipalGroupModel> roleModels = new HashSet<PrincipalGroupModel>(model.getGroups());
   CollectionUtils.filter(
       roleModels,
       PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUnitModel.class)));
   CollectionUtils.filter(
       roleModels,
       PredicateUtils.notPredicate(PredicateUtils.instanceofPredicate(B2BUserGroupModel.class)));
   for (final PrincipalGroupModel role : roleModels) {
     // only display allowed usergroups
     if (energizerGroupsLookUpStrategy.getUserGroups().contains(role.getUid())) {
       roles.add(role.getUid());
     }
   }
   target.setRoles(roles);
 }
예제 #6
0
 public List<String> getAvailablePhoneNumbers() {
   List<String> phoneNumbers =
       Arrays.asList(
           phoneNumber, additionalPhoneNumber1, additionalPhoneNumber2, additionalPhoneNumber3);
   phoneNumbers = new ArrayList<String>(phoneNumbers);
   CollectionUtils.filter(
       phoneNumbers,
       new Predicate() {
         public boolean evaluate(Object input) {
           if (input instanceof String) {
             return StringUtils.isNotBlank((String) input);
           }
           return false;
         }
       });
   return phoneNumbers;
 }
  @Test
  public void shouldReturnOnlyStreamResources() {
    List<Content> contents = getContents();
    List<ResourceDto> expected = createInputData(contents);

    CollectionUtils.filter(
        expected,
        new Predicate() {
          @Override
          public boolean evaluate(Object object) {
            return object instanceof ResourceDto
                && !equalsIgnoreCase(((ResourceDto) object).getType(), "string");
          }
        });

    List<ResourceDto> actual =
        ResourceFilter.filter(createGridSettings("", false, true, ""), contents);

    assertEquals(expected, actual);
  }
 /**
  * Returns a map ambience -> set of files.
  *
  * @param global initial set of files to consider
  * @return a map ambience -> set of files
  */
 @SuppressWarnings("unchecked")
 private Map<Ambience, List<File>> getAmbienceFilesList(List<File> global) {
   // Create a map ambience -> set of files
   Map<Ambience, List<File>> hmAmbienceFiles = new HashMap<Ambience, List<File>>(5);
   // For performance, we find unique ambiences in from and to transitions
   Set<Ambience> ambiences = new HashSet<Ambience>(5);
   for (Transition tr : transitions) {
     ambiences.add(tr.getFrom());
     ambiences.add(tr.getTo());
   }
   // Fill null key
   hmAmbienceFiles.put(null, (List<File>) ((ArrayList<File>) global).clone());
   // Fill all ambiences
   for (Ambience ambience : ambiences) {
     List<File> all = (List<File>) ((ArrayList<File>) global).clone();
     CollectionUtils.filter(all, new JajukPredicates.AmbiencePredicate(ambience));
     hmAmbienceFiles.put(ambience, all);
   }
   return hmAmbienceFiles;
 }
예제 #9
0
  /**
   * Executes a <code>HibernateQuery</code> using the currently defined <code>
   * CriteriaSearchParameter</code>s, and returns a java.util.List containing the query results.
   *
   * @return result The result of the query.
   * @throws org.hibernate.HibernateException
   */
  public final java.util.List executeAsList() throws org.hibernate.HibernateException {
    // add ordering
    if (this.orderList.size() > 0) {
      java.util.Collections.sort(this.orderList, new ParameterComparator());
      for (java.util.Iterator orderIterator = this.orderList.iterator();
          orderIterator.hasNext(); ) {
        CriteriaSearchParameter parameter = (CriteriaSearchParameter) orderIterator.next();
        int direction = parameter.getOrderDirection();
        if (direction == CriteriaSearchParameter.ORDER_ASC) {
          this.rootCriteria.addOrder(
              org.hibernate.criterion.Order.asc(parameter.getParameterPattern()));
        } else {
          this.rootCriteria.addOrder(
              org.hibernate.criterion.Order.desc(parameter.getParameterPattern()));
        }
      }
    }

    // set the first result if configured
    if (this.configuration.getFirstResult() != null) {
      this.rootCriteria.setFirstResult(this.configuration.getFirstResult().intValue());
    }

    // set the fetch size if configured
    if (this.configuration.getFetchSize() != null) {
      this.rootCriteria.setFetchSize(this.configuration.getFetchSize().intValue());
    }

    // limit the maximum result if configured
    if (this.configuration.getMaximumResultSize() != null) {
      this.rootCriteria.setMaxResults(this.configuration.getMaximumResultSize().intValue());
    }

    // Hibernate does not support a 'unique' identifier. As a search may contain outer joins,
    // duplicates in the resultList are possible. We eliminate any duplicates here, creating a
    // distinctified resultSet (Suggestion from Hibernate itself; see www.hibernate.org's FAQ's).
    final java.util.List result = this.rootCriteria.list();
    org.apache.commons.collections.CollectionUtils.filter(
        result, org.apache.commons.collections.functors.UniquePredicate.getInstance());
    return result;
  }
  @Test
  public void shouldReturnOnlyWithGivenName() {
    final String givenName = "files";

    List<Content> contents = getContents();
    List<ResourceDto> expected = createInputData(contents);

    CollectionUtils.filter(
        expected,
        new Predicate() {
          @Override
          public boolean evaluate(Object object) {
            return object instanceof ResourceDto
                && startsWithIgnoreCase(((ResourceDto) object).getName(), givenName);
          }
        });

    List<ResourceDto> actual =
        ResourceFilter.filter(createGridSettings(givenName, true, true, ""), contents);

    assertEquals(expected, actual);
  }
  public ITargetDefinition saveMavenTargetDefinition(
      Shell shell, IProject targetProject, MavenBundleContainer mavenBundleContainer) {
    try {
      ITargetDefinition newTarget = loadMavenTargetDefinition(mavenBundleContainer);

      IFile targetFile = targetProject.getFile(PDE_TARGET_TARGET);

      // Ensure plugins folder is reset
      IFolder pluginsFolder = targetProject.getFolder(PDE_TARGET_PLUGINS);
      if (pluginsFolder.exists()) {
        pluginsFolder.delete(true, null);
      }
      pluginsFolder.create(true, true, null);

      // Ensure otherPlugins folder exists
      IFolder otherPluginsFolder = targetProject.getFolder(PDE_TARGET_OTHER_PLUGINS);
      if (!otherPluginsFolder.exists()) {
        otherPluginsFolder.create(true, true, null);
      }

      File pluginsFolderFile = pluginsFolder.getLocation().toFile();

      // Copy all maven dependencies in pluginsFolder

      // Keep all project artifactIds to ensure they are used instead of any other dependencies
      final HashSet<String> projectArtifactId = new HashSet<String>();
      for (IMavenProjectFacade mavenProject : mavenBundleContainer.getMavenProjects()) {
        projectArtifactId.add(mavenProject.getArtifactKey().getArtifactId());
      }

      Collection<Artifact> mostRecentArtifacts =
          getMostRecentArtifacts(mavenBundleContainer.getArtifacts(null));

      CollectionUtils.filter(
          mostRecentArtifacts,
          new Predicate() {
            @Override
            public boolean evaluate(Object param) {
              Artifact artifact = (Artifact) param;

              return !projectArtifactId.contains(artifact.getArtifactId());
            }
          });

      for (Artifact artifact : mostRecentArtifacts) {
        try {
          File bundleFile = artifact.getFile().getAbsoluteFile();
          if (bundleFile.isFile()) {
            FileUtils.copyFileToDirectory(bundleFile, pluginsFolderFile);
          }
        } catch (IOException e) {
          throw e;
        }
      }

      // Update targetFile with the DirectoryBundelContainer if not already present
      ITargetHandle targetHandle = targetPlatformService.getTarget(targetFile);
      ITargetDefinition directoryTargetDefinition = targetHandle.getTargetDefinition();

      String pluginsFolderPath = pluginsFolderFile.getAbsolutePath();
      String otherPluginsPath = otherPluginsFolder.getLocation().toFile().getAbsolutePath();

      if (targetFile.exists()) {
        // Find already existing DirectoryBundleContainer for maven repository path
        addBundleContainerToTargetDefinitionIfNotPresent(
            directoryTargetDefinition, pluginsFolderPath);
        addBundleContainerToTargetDefinitionIfNotPresent(
            directoryTargetDefinition, otherPluginsPath);
      } else {
        directoryTargetDefinition.setBundleContainers(
            new IBundleContainer[] {
              new DirectoryBundleContainer(pluginsFolderPath),
              new DirectoryBundleContainer(otherPluginsPath)
            });
      }

      // Refresh project folder tree
      NullProgressMonitor monitor = new NullProgressMonitor();
      targetFile.refreshLocal(IResource.DEPTH_INFINITE, monitor);
      pluginsFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
      otherPluginsFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
      targetProject.refreshLocal(IResource.DEPTH_INFINITE, monitor);

      // Save target definition
      targetPlatformService.saveTargetDefinition(directoryTargetDefinition);

      LoadTargetDefinitionJob.load(directoryTargetDefinition);
      return newTarget;
    } catch (Exception e) {
      MessageBox msgbox = new MessageBox(shell, SWT.ALPHA);

      msgbox.setMessage(
          "Unable to create PDE Target, delelete file " + PDE_TARGET_TARGET + " in your project");
      msgbox.setText("Error while creating PDE Target");
      msgbox.open();

      e.printStackTrace();

      throw new RuntimeException("Unable to create target", e);
    }
  }