/*
 * Waltz - Enterprise Architecture
 * Copyright (C) 2016  Khartec Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.khartec.waltz.service.perspective_definition;

import com.khartec.waltz.data.perspective_definition.PerspectiveDefinitionDao;
import com.khartec.waltz.model.perspective.PerspectiveDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.khartec.waltz.common.Checks.checkNotNull;

@Service
public class PerspectiveDefinitionService {

    private final PerspectiveDefinitionDao perspectiveDefinitionDao;

    @Autowired
    public PerspectiveDefinitionService(PerspectiveDefinitionDao perspectiveDefinitionDao) {
        checkNotNull(perspectiveDefinitionDao, "perspectiveDefinitionDao cannot be null");
        this.perspectiveDefinitionDao = perspectiveDefinitionDao;
    }

    public List<PerspectiveDefinition> findAll() {
        return perspectiveDefinitionDao.findAll();
    }

    public void create(PerspectiveDefinition perspectiveDefinition) {
        checkNotNull(perspectiveDefinition, "perspectiveDefinition cannot be null");
        perspectiveDefinitionDao.create(perspectiveDefinition);

        System.out.println("Creating: "+perspectiveDefinition);   
    }
}

@@ -946,16 +946,73 @@
 nition;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -1253,16 +1253,116 @@
 vice %7B%0A%0A
+    private static final Logger LOG = LoggerFactory.getLogger(PerspectiveDefinitionService.class);%0A%0A
     priv
@@ -1423,16 +1423,17 @@
 onDao;%0A%0A
+%0A
     @Aut
@@ -1688,32 +1688,33 @@
 tionDao;%0A    %7D%0A%0A
+%0A
     public List%3C
@@ -1806,16 +1806,17 @@
 %0A    %7D%0A%0A
+%0A
     publ
@@ -1822,12 +1822,15 @@
 lic 
-void
+boolean
  cre
@@ -1965,23 +1965,41 @@
 null%22);%0A
+%0A
        
+ boolean result =
  perspec
@@ -2047,17 +2047,16 @@
 ition);%0A
-%0A
         
@@ -2060,39 +2060,188 @@
    S
-ystem.out.println(%22Creating: %22+
+tring msg = result%0A                ? %22Created new perspective definition: %7B%7D%22%0A                : %22Ignoring new perspective definition: %7B%7D, as already exists%22;%0A        LOG.info(msg, 
 pers
@@ -2259,19 +2259,39 @@
 nition);
+%0A
    
+     return result;
 %0A    %7D%0A%7D

Allow admins to create perspective definitions #1463