/*
 * Copyright 2011 JBoss Inc
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package org.drools.guvnor.server;

import java.util.Map;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.drools.guvnor.client.rpc.ConfigurationService;
import org.drools.guvnor.server.configurations.ApplicationPreferencesInitializer;
import org.drools.guvnor.server.configurations.ApplicationPreferencesLoader;
import org.drools.guvnor.server.util.BeanManagerUtils;
import org.drools.guvnor.server.util.TestEnvironmentSessionHelper;
import org.drools.repository.RulesRepository;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;

public class ConfigurationServiceImplementation
        extends RemoteServiceServlet
        implements ConfigurationService {
    
    @Inject
    private RulesRepository repository;

    public Map<String, String> loadPreferences() {
        Map<String, String> preferences = ApplicationPreferencesLoader.load();
        ApplicationPreferencesInitializer.setSystemProperties(preferences);
        return preferences;
    }

//    protected RulesRepository getRepository() {
//        BeanManager beanManager = (BeanManager) getServletContext()
//                .getAttribute("org.jboss.weld.environment.servlet.javax.enterprise.inject.spi.BeanManager");
//        return (RulesRepository) beanManager.getBeans("repository").iterator().next();
//        BeanManagerLocator beanManagerLocator = new BeanManagerLocator();
//        if (beanManagerLocator.isBeanManagerAvailable()) {
//            return (RulesRepository) BeanManagerUtils.getInstance("repository");
//        } else {
//            try {
//                return new RulesRepository(TestEnvironmentSessionHelper.getSession(false));
//            } catch (Exception e) {
//                throw new IllegalStateException("Unable to get repo to run tests", e);
//            }
//
//        }
//    }

}

@@ -1369,65 +1369,8 @@
 ce %7B
-%0A    %0A    @Inject%0A    private RulesRepository repository;
 %0A%0A  
@@ -1612,846 +1612,6 @@
  %7D%0A%0A
-//    protected RulesRepository getRepository() %7B%0A//        BeanManager beanManager = (BeanManager) getServletContext()%0A//                .getAttribute(%22org.jboss.weld.environment.servlet.javax.enterprise.inject.spi.BeanManager%22);%0A//        return (RulesRepository) beanManager.getBeans(%22repository%22).iterator().next();%0A//        BeanManagerLocator beanManagerLocator = new BeanManagerLocator();%0A//        if (beanManagerLocator.isBeanManagerAvailable()) %7B%0A//            return (RulesRepository) BeanManagerUtils.getInstance(%22repository%22);%0A//        %7D else %7B%0A//            try %7B%0A//                return new RulesRepository(TestEnvironmentSessionHelper.getSession(false));%0A//            %7D catch (Exception e) %7B%0A//                throw new IllegalStateException(%22Unable to get repo to run tests%22, e);%0A//            %7D%0A//%0A//        %7D%0A//    %7D%0A%0A
 %7D%0A

remove dead code: Repository injection