Commit aece94f7 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added user script service

parent bd76cf20
......@@ -47,6 +47,7 @@ import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller;
import nl.uva.sne.drip.api.service.ToscaService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.types.CloudCredentials;
import nl.uva.sne.drip.commons.types.LoginKey;
......@@ -64,8 +65,10 @@ public class ProvisionController {
@Value("${message.broker.host}")
private String messageBrokerHost;
@Autowired
private ToscaDao toscaDao;
private ToscaService toscaService;
@Autowired
private CloudCredentialsDao cloudCredentialsDao;
......@@ -140,6 +143,9 @@ public class ProvisionController {
private List<Parameter> buildCertificatesParam(CloudCredentials cred) {
List<LoginKey> loginKeys = cred.getLoginKeys();
if (loginKeys == null || loginKeys.isEmpty()) {
throw new BadRequestException("Log in keys can't be empty");
}
List<Parameter> parameters = new ArrayList<>();
for (LoginKey lk : loginKeys) {
String domainName = lk.getAttributes().get("domain_name");
......@@ -158,7 +164,7 @@ public class ProvisionController {
}
private List<Parameter> buildTopologyParams(String planID) throws JSONException {
ToscaRepresentation plan = toscaDao.findOne(planID);
ToscaRepresentation plan = toscaService.get(planID, ToscaRepresentation.Type.PLAN);
if (plan == null) {
throw new NotFoundException();
}
......@@ -174,7 +180,7 @@ public class ProvisionController {
Set<String> ids = plan.getLowerLevelIDs();
for (String lowID : ids) {
plan = toscaDao.findOne(lowID);
plan = toscaService.get(lowID, ToscaRepresentation.Type.PLAN);
topology = new Parameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(plan.getKvMap()));
......@@ -202,6 +208,7 @@ public class ProvisionController {
}
private List<Parameter> buildScriptParams(String userScriptID) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
......
......@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
......
......@@ -110,4 +110,12 @@ public class ToscaService {
public ToscaDao getDao() {
return dao;
}
public ToscaRepresentation get(String planID, ToscaRepresentation.Type type) {
ToscaRepresentation tosca = dao.findOne(planID);
if (tosca == null || !tosca.getType().equals(type)) {
throw new NotFoundException();
}
return tosca;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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 nl.uva.sne.drip.api.service;
import java.util.Collection;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.api.dao.UserDao;
import nl.uva.sne.drip.api.dao.UserScriptDao;
import nl.uva.sne.drip.commons.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class UserScriptService {
@Autowired
UserScriptDao dao;
public UserScriptDao getDao() {
return dao;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment