/*
Facet Methods
517542
@Override
   public WebAppDescriptor getConfig()
   {
      FileResource<?> configFile = getConfigFile();
      WebAppDescriptor descriptor;
      if (configFile.exists())
      {

         DescriptorImporter<WebAppDescriptor> importer = Descriptors.importAs(WebAppDescriptor.class);
         InputStream inputStream = configFile.getResourceInputStream();
         try
         {
            descriptor = importer.fromStream(inputStream);
         }
         finally
         {
            Streams.closeQuietly(inputStream);
         }
      }
      else
      {
         descriptor = Descriptors.create(WebAppDescriptor.class);
         String projectName = getFaceted().getFacet(MetadataFacet.class).getProjectName();
         WebAppDescriptor unit = descriptor
                  .version("2.5")
                  .displayName(projectName)
                  .createSessionConfig()
                  .sessionTimeout(30).up();
         // FORGE-657
         unit.createMimeMapping().extension("ico").mimeType("image/x-icon");
         configFile.setContents(descriptor.exportAsString());
      }
      return descriptor;
   }
1071654
private Component prepareFolderFacets(CmsSolrResultList solrResultList, CmsSearchResultWrapper resultWrapper) {

        FacetField folderFacets = solrResultList.getFacetField(CmsListManager.FIELD_PARENT_FOLDERS);
        I_CmsSearchControllerFacetField facetController = resultWrapper.getController().getFieldFacets().getFieldFacetController().get(
            CmsListManager.FIELD_PARENT_FOLDERS);
        if ((folderFacets != null) && (folderFacets.getValueCount() > 0)) {
            VerticalLayout folderLayout = new VerticalLayout();
            for (final Count value : filterFolderFacets(folderFacets.getValues())) {
                Button folder = new Button(getFolderLabel(value.getName()) + " (" + value.getCount() + ")");
                folder.addStyleName(ValoTheme.BUTTON_TINY);
                folder.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                Boolean selected = facetController.getState().getIsChecked().get(value.getName());
                if ((selected != null) && selected.booleanValue()) {
                    folder.addStyleName(SELECTED_STYLE);
                }
                folder.addClickListener(new ClickListener() {

                    private static final long serialVersionUID = 1L;

                    public void buttonClick(ClickEvent event) {

                        if (isSelected(event.getComponent())) {
                            resetFacetsAndSearch();
                        } else {
                            selectFieldFacet(CmsListManager.FIELD_PARENT_FOLDERS, value.getName());
                        }
                    }
                });
                folderLayout.addComponent(folder);
            }
            Panel folderPanel = new Panel(CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_FACET_FOLDERS_0));
            folderPanel.setContent(folderLayout);
            return folderPanel;
        } else {
            return null;
        }
    }
524597
public Query setFacetFilters(List<String> facets) {
    JSONArray obj = new JSONArray();
    for (String facet : facets) {
      obj.put(facet);
    }
    this.facetFilters = obj.toString();
    return this;
  }
956544
public function moveFacetUp(Facet $facet)
    {
        $currentPosition = $facet->getPosition();

        if ($currentPosition < $this->om->count('Claroline\CoreBundle\Entity\Facet\Facet') - 1) {
            $nextPosition = $currentPosition + 1;
            $nextFacet = $this->om
                ->getRepository('ClarolineCoreBundle:Facet\Facet')
                ->findOneBy(array('position' => $nextPosition));
            $nextFacet->setPosition($currentPosition);
            $facet->setPosition($nextPosition);
            $this->om->persist($nextFacet);
            $this->om->persist($facet);
            $this->om->flush();
        }
    }
43069
public void setFaceDetails(java.util.Collection<FaceDetail> faceDetails) {
        if (faceDetails == null) {
            this.faceDetails = null;
            return;
        }

        this.faceDetails = new java.util.ArrayList<FaceDetail>(faceDetails);
    }
1175881
@Override
  public FacetResult getFacetResult(String name) {
    if (facets == null || facets.isEmpty()) {
      return null;
    }
    return facets.get(name);
  }
695811
private void validateFacetFields(String[] facetFieldList) {
        if(facetFieldList == null || facetFieldList.length == 0){
            return;
        }
        for (String facetfield : facetFieldList){
            if(schema.getColumnIndex(facetfield) < 0){
                throw new IllegalArgumentException("Facet field:"+facetfield+", not found in schema");
            }
        }

    }
356558
@SuppressWarnings({"WeakerAccess", "unused"}) // For library users
    public Searcher addFacet(String... attributes) {
        for (String attribute : attributes) {
            final Integer value = facetRequestCount.get(attribute);
            facetRequestCount.put(attribute, value == null ? 1 : value + 1);
            if (value == null || value == 0) {
                facets.add(attribute);
            }
        }
        rebuildQueryFacets();
        return this;
    }
348021
protected function getFacetParameters() {
        $facetParameters = [];
        $facetParameters['facet'] = 'true';
        $facetParameters['facet.mincount'] = $this->getMinCount();
        $facetParameters['facet.limit'] = $this->getLimit();
        $facetParameters['facet.field'] = $this->getFields();

        foreach ($this->getAdditionalParameters() as $additionalParameterKey => $additionalParameterValue) {
            $facetParameters[$additionalParameterKey] = $additionalParameterValue;
        }

        if ($facetParameters['json.facet']) {
            $facetParameters['json.facet'] = json_encode($facetParameters['json.facet']);
        }

        $facetParameters = $this->applySorting($facetParameters);
        return $facetParameters;
    }
1011367
public function orderPanels(Facet $facet)
    {
        $params = $this->request->query->all();
        $ids = [];

        foreach ($params['ids'] as $value) {
            $ids[] = (int) str_replace('panel-', '', $value);
        }

        $this->facetManager->orderPanels($ids, $facet);

        return new Response('success');
    }
93372
public SimpleOrderedMap<Object> create(ComponentFacet facet, Boolean encode)
      throws IOException {
    SimpleOrderedMap<Object> mtasFacetResponse = new SimpleOrderedMap<>();
    mtasFacetResponse.add("key", facet.key);
    HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<>();
    for (int i = 0; i < facet.baseFields.length; i++) {
      if (facet.baseFunctionList[i] != null) {
        for (MtasDataCollector<?, ?> functionDataCollector : facet.baseFunctionList[i]
            .keySet()) {
          SubComponentFunction[] tmpSubComponentFunctionList = facet.baseFunctionList[i]
              .get(functionDataCollector);
          if (tmpSubComponentFunctionList != null) {
            HashMap<String, MtasSolrMtasResult> tmpList = new HashMap<>();
            for (SubComponentFunction tmpSubComponentFunction : tmpSubComponentFunctionList) {
              tmpList.put(tmpSubComponentFunction.key,
                  new MtasSolrMtasResult(tmpSubComponentFunction.dataCollector,
                      tmpSubComponentFunction.dataType,
                      tmpSubComponentFunction.statsType,
                      tmpSubComponentFunction.statsItems, null, null));
            }
            functionData.put(functionDataCollector, tmpList);
          }
        }
      }
    }
    MtasSolrMtasResult data = new MtasSolrMtasResult(facet.dataCollector,
        facet.baseDataTypes, facet.baseStatsTypes, facet.baseStatsItems, null,
        facet.baseSortTypes, facet.baseSortDirections, null, facet.baseNumbers,
        functionData);

    if (encode) {
      mtasFacetResponse.add("_encoded_list", MtasSolrResultUtil.encode(data));
    } else {
      mtasFacetResponse.add("list", data);
      MtasSolrResultUtil.rewrite(mtasFacetResponse, searchComponent);
    }
    return mtasFacetResponse;
  }
832775
@Override
  public FacetResult[] getFacetResults() {
    if (facets == null || facets.isEmpty()) {
      return new FacetResult[0];
    }
    Collection<FacetResult> facetResults = facets.values();
    return facetResults.toArray(new FacetResult[facetResults.size()]);
  }
204027
public function serialize(Facet $facet, array $options = [])
    {
        return [
          'id' => $facet->getUuid(),
          'title' => $facet->getName(),
          'position' => $facet->getPosition(),
          'display' => [
            'creation' => $facet->getForceCreationForm(),
          ],
          'roles' => array_map(function (Role $role) {
              return $this->roleSerializer->serialize($role, [Options::SERIALIZE_MINIMAL]);
          }, $facet->getRoles()->toArray()),
          'meta' => [
              'main' => $facet->isMain(),
          ],
          'sections' => array_map(function ($panel) use ($options) { // todo check user rights
              return $this->pfSerializer->serialize($panel, $options);
          }, $facet->getPanelFacets()->toArray()),
        ];
    }
777246
@Override
   protected void implementInterface(InterfaceCapableSource<?> source, Iterable<String> value, JavaSourceFacet facet)
   {
      for (String type : value)
      {
         source.addInterface(type);
      }
   }
180952
@SuppressWarnings({"WeakerAccess", "unused"}) // For library users
    public Searcher deleteFacet(String... attributes) {
        for (String attribute : attributes) {
            facetRequestCount.put(attribute, 0);
            facets.remove(attribute);
        }
        rebuildQueryFacets();
        return this;
    }
212058
@Override
    protected Collection<Object> elementsOf(Object facetValue) {
        int length = Array.getLength(facetValue);
        List<Object> list = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            list.add(Array.get(facetValue, i));
        }
        return list;
    }
654836
@Override
    protected Collection<Object> elementsOf(Map<Object, Object> facetValue) {
        return facetValue.values();
    }