<commit_before>package org.oasis.datacore.core.meta;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.oasis.datacore.common.context.DCRequestContextProvider;
import org.oasis.datacore.common.context.DCRequestContextProviderFactory;
import org.oasis.datacore.core.meta.model.DCField;
import org.oasis.datacore.core.meta.model.DCModel;
import org.oasis.datacore.core.meta.model.DCModelBase;
import org.oasis.datacore.core.meta.model.DCModelService;
import org.oasis.datacore.core.meta.pov.DCProject;
import org.oasis.datacore.core.meta.pov.ProjectException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * TODO readonly : get & set map only for tests, LATER admin using another (inheriting) model ?!?
 * => LATER extract update methods in another admin interface
 * @author mdutoo
 *
 */
@Service("modelService")
public class DataModelServiceImpl implements DCModelService {
   
   /** to use default projects building */
   @Value("${datacore.devmode}")
   private boolean devmode;
   @Autowired
   ///@Qualifier("datacore.cxfJaxrsApiProvider")
   //protected DCRequestContextProvider requestContextProvider;
   protected DCRequestContextProviderFactory requestContextProviderFactory;
   /** to inject caching... */
   @Resource(name="modelService")// or @PostConstruct ; @Autowired doesn't work http://stackoverflow.com/questions/5152686/self-injection-with-spring
   protected DCModelService dataModelService;
   
   //TODO modelTo(ModelImplementation)CollectionMap ?
   //TODO (modelDefinitionMap) modelImplementationConfigurationMap, modelImplementationInstanciationMap, modelToImplementatioI(|C)Map
   //TODO ModelImplementationConfiguration MICCStrategy.checkAccepted(model, or Resource ex. if depends from contributor vs model owner ??)
   //TODO having MICCRootTypesStrategy.rootTypes = cofr, coit... or MICCModelOwnerStrategy.modelOwners = cofr_owners, coit_owners...
   
   private Map<String,DCProject> projectMap = new HashMap<String, DCProject>();
   
   // NEW TODO migrate
   @Override
   public DCModelBase getModelBase(String type) {
      DCProject project = getProject(); // NB. can't be null
      // NB. devmode default alt models building is done in there :
      return project.getModel(type); // TODO if isStorageOnly, get inherited model ?
   }
   @Override
   public DCModelBase getNonLocalModel(String type) {
      DCProject project = getProject(); // NB. can't be null
      // NB. devmode default alt models building is done in there :
      return project.getNonLocalModel(type);
   }
   @Override
   public DCModelBase getDefinitionModel(DCModelBase model) {
      DCProject project = getProject(model.getProjectName()); // NB. can't be null
      return project.getDefinitionModel(model);
   }
   @Override
   public DCModelBase getStorageModel(DCModelBase model) {
      DCProject project = getProject(model.getProjectName()); // NB. can't be null
      return project.getStorageModel(model);
   }
   /**
    * TODO cache
    * @param model must be storage
    * @return models having given model as storage model
    */
   @Override
   public Collection<DCModelBase> getStoredModels(DCModelBase model) {
      ArrayList<DCModelBase> storedModels = new ArrayList<DCModelBase>();
      HashSet<String> alreadyDoneModelNames = new HashSet<String>();
      for (DCProject p : this.getProjects()) {
         /*if (p.getName().equals(project.getName())) {
            continue;
         }*/
         for (DCModelBase m : p.getModels()) { // including visible projects'
            if (!m.getMixinNames().contains(model.getName())
                  || alreadyDoneModelNames.contains(m.getName())) { // && !model.getName().equals(m.getName())
               continue;
            }
            alreadyDoneModelNames.add(m.getName());
            DCModelBase storageModel = p.getStorageModel(m);
            if (storageModel == null || !storageModel.getAbsoluteName().equals(model.getAbsoluteName())) {
               continue;
            }<commit_msg>patched getStoredModels() and therefore indexes<commit_after>package org.oasis.datacore.core.meta;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.oasis.datacore.common.context.DCRequestContextProvider;
import org.oasis.datacore.common.context.DCRequestContextProviderFactory;
import org.oasis.datacore.core.meta.model.DCField;
import org.oasis.datacore.core.meta.model.DCModel;
import org.oasis.datacore.core.meta.model.DCModelBase;
import org.oasis.datacore.core.meta.model.DCModelService;
import org.oasis.datacore.core.meta.pov.DCProject;
import org.oasis.datacore.core.meta.pov.ProjectException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * TODO readonly : get & set map only for tests, LATER admin using another (inheriting) model ?!?
 * => LATER extract update methods in another admin interface
 * @author mdutoo
 *
 */
@Service("modelService")
public class DataModelServiceImpl implements DCModelService {
   
   /** to use default projects building */
   @Value("${datacore.devmode}")
   private boolean devmode;
   @Autowired
   ///@Qualifier("datacore.cxfJaxrsApiProvider")
   //protected DCRequestContextProvider requestContextProvider;
   protected DCRequestContextProviderFactory requestContextProviderFactory;
   /** to inject caching... */
   @Resource(name="modelService")// or @PostConstruct ; @Autowired doesn't work http://stackoverflow.com/questions/5152686/self-injection-with-spring
   protected DCModelService dataModelService;
   
   //TODO modelTo(ModelImplementation)CollectionMap ?
   //TODO (modelDefinitionMap) modelImplementationConfigurationMap, modelImplementationInstanciationMap, modelToImplementatioI(|C)Map
   //TODO ModelImplementationConfiguration MICCStrategy.checkAccepted(model, or Resource ex. if depends from contributor vs model owner ??)
   //TODO having MICCRootTypesStrategy.rootTypes = cofr, coit... or MICCModelOwnerStrategy.modelOwners = cofr_owners, coit_owners...
   
   private Map<String,DCProject> projectMap = new HashMap<String, DCProject>();
   
   // NEW TODO migrate
   @Override
   public DCModelBase getModelBase(String type) {
      DCProject project = getProject(); // NB. can't be null
      // NB. devmode default alt models building is done in there :
      return project.getModel(type); // TODO if isStorageOnly, get inherited model ?
   }
   @Override
   public DCModelBase getNonLocalModel(String type) {
      DCProject project = getProject(); // NB. can't be null
      // NB. devmode default alt models building is done in there :
      return project.getNonLocalModel(type);
   }
   @Override
   public DCModelBase getDefinitionModel(DCModelBase model) {
      DCProject project = getProject(model.getProjectName()); // NB. can't be null
      return project.getDefinitionModel(model);
   }
   @Override
   public DCModelBase getStorageModel(DCModelBase model) {
      DCProject project = getProject(model.getProjectName()); // NB. can't be null
      return project.getStorageModel(model);
   }
   /**
    * TODO cache
    * @param model must be storage
    * @return models having given model as storage model
    */
   @Override
   public Collection<DCModelBase> getStoredModels(DCModelBase model) {
      ArrayList<DCModelBase> storedModels = new ArrayList<DCModelBase>();
      HashSet<String> alreadyDoneModelNames = new HashSet<String>();
      for (DCProject p : this.getProjects()) {
         /*if (p.getName().equals(project.getName())) {
            continue;
         }*/
         for (DCModelBase m : p.getModels()) { // including visible projects'
            if (!m.getMixinNames().contains(model.getName())
                  && !model.getName().equals(m.getName()) // NB. m.mixins do not contain m
                  || alreadyDoneModelNames.contains(m.getName())) {
               continue;
            }
            alreadyDoneModelNames.add(m.getName());
            DCModelBase storageModel = p.getStorageModel(m);
            if (storageModel == null || !storageModel.getAbsoluteName().equals(model.getAbsoluteName())) {
               continue;
            }
{'fraction_non_alphanumeric': 0.1062543594512904, 'fraction_numerical': 0.0016275284817484307, 'mean_word_length': 3.7504141358365546, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2774384', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2390, 'n_words': 558}