Skip to content
Snippets Groups Projects
Commit 80c20c2c authored by Hugo Blanquart's avatar Hugo Blanquart
Browse files

mvn before pizza

parent 2eb5c629
No related branches found
No related tags found
No related merge requests found
...@@ -5,12 +5,43 @@ import org.glassfish.jersey.server.ResourceConfig; ...@@ -5,12 +5,43 @@ import org.glassfish.jersey.server.ResourceConfig;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.ws.rs.ApplicationPath; import javax.ws.rs.ApplicationPath;
import fr.ulille.iut.pizzaland.beans.Ingredient;
import fr.ulille.iut.pizzaland.dao.IngredientDao;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
@ApplicationPath("api/v1/") @ApplicationPath("api/v1/")
public class ApiV1 extends ResourceConfig { public class ApiV1 extends ResourceConfig {
private static final Logger LOGGER = Logger.getLogger(ApiV1.class.getName()); private static final Logger LOGGER = Logger.getLogger(ApiV1.class.getName());
public ApiV1() { public ApiV1() {
packages("fr.ulille.iut.pizzaland"); packages("fr.ulille.iut.pizzaland");
String environment = System.getenv("PIZZAENV");
if ( environment != null && environment.equals("withdb") ) {
LOGGER.info("Loading with database");
Jsonb jsonb = JsonbBuilder.create();
try {
FileReader reader = new FileReader( getClass().getClassLoader().getResource("ingredients.json").getFile() );
List<Ingredient> ingredients = JsonbBuilder.create().fromJson(reader, new ArrayList<Ingredient>(){}.getClass().getGenericSuperclass());
IngredientDao ingredientDao = BDDFactory.buildDao(IngredientDao.class);
ingredientDao.dropTable();
ingredientDao.createTable();
for ( Ingredient ingredient: ingredients) {
ingredientDao.insert(ingredient.getName());
}
} catch ( Exception ex ) {
throw new IllegalStateException(ex);
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment