cz.muni.fi.editor.services.api.requests.decline.RequestDeclinerOrganizationCreate.java Source code

Java tutorial

Introduction

Here is the source code for cz.muni.fi.editor.services.api.requests.decline.RequestDeclinerOrganizationCreate.java

Source

/*
*Copyright  2016 Dominik Szalai (emptulik@gmail.com)
*
*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 cz.muni.fi.editor.services.api.requests.decline;

import cz.muni.fi.editor.database.dao.OrganizationDAO;
import cz.muni.fi.editor.database.dao.RequestDAO;
import cz.muni.fi.editor.database.domain.requests.Request;
import cz.muni.fi.editor.database.domain.requests.RequestState;
import cz.muni.fi.editor.services.api.requests.AbstractRequestWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * Created by Dominik Szalai - emptulik at gmail.com on 28.10.2016.
 */
public class RequestDeclinerOrganizationCreate extends AbstractRequestWorker implements RequestDecliner {
    @Autowired
    private OrganizationDAO organizationDAO;
    @Autowired
    private RequestDAO requestDAO;

    @Override
    @Transactional
    public void decline(Request request) {
        request.setChangeStateDate(LocalDateTime.now());
        request.setApprover(getPrincipal());
        request.setState(RequestState.REJECTED);

        requestDAO.update(request);

        organizationDAO.delete(request.getTargetId());
    }
}