/******************************************************************************* * Copyright (c) 2012-2017 Codenvy, S.A. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ package org.eclipse.che.plugin.maven.server.projecttype.handler; import org.eclipse.che.api.core.ConflictException; import org.eclipse.che.api.core.ForbiddenException; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.project.server.handlers.CreateProjectHandler; import org.eclipse.che.api.project.server.type.AttributeValue; import org.eclipse.che.api.vfs.Path; import org.eclipse.che.plugin.maven.shared.MavenAttributes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Singleton; import java.util.HashMap; import java.util.Map; import java.util.Set; /** * @author gazarenkov */ @Singleton public class MavenProjectGenerator implements CreateProjectHandler { private static final Logger LOG = LoggerFactory.getLogger(MavenProjectGenerator.class); private final Map<String, GeneratorStrategy> strategies = new HashMap<>(); @Inject public MavenProjectGenerator(Set<GeneratorStrategy> generatorStrategies) throws ServerException { for (GeneratorStrategy generatorStrategy : generatorStrategies) { strategies.put(generatorStrategy.getId(), generatorStrategy); } } @Override public String getProjectType() { return MavenAttributes.MAVEN_ID; } @Override public void onCreateProject(Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException { if (options == null || options.isEmpty() || !options.containsKey("type")) { strategies.get(MavenAttributes.SIMPLE_GENERATION_STRATEGY).generateProject(projectPath, attributes, options); } else { if (strategies.containsKey(options.get("type"))) { strategies.get(options.get("type")).generateProject(projectPath, attributes, options); } else { String errorMsg = String.format("Generation strategy %s not found", options.get("type")); LOG.warn("MavenProjectGenerator", errorMsg); throw new ServerException(errorMsg); } } } }