2015年7月19日日曜日

[メタデータエディタ]UpdateSubstanceServiceImpl

サブスタンス更新サービスの実装クラス。

package service.impl;

import service.DomainDrivenService;
import service.UpdateSubstanceService;
import service.param.ServiceInputParameter;
import service.param.ServiceOutputParameter;
import service.param.SipUpdateSubstanceService;
import service.param.SopUpdateSubstanceService;
import util.CopyUtil;
import domain.SubstanceDomain;
import domain.SubstanceRepository;
import dto.SubstanceDto;
import entity.Substance;

/**
 * サブスタンス更新サービス(実装)
 */
public class UpdateSubstanceServiceImpl implements DomainDrivenService,
        UpdateSubstanceService {

    /** サブスタンスリポジトリ */
    private SubstanceRepository substanceRepository = null;

    public SubstanceRepository getSubstanceRepository() {
        return substanceRepository;
    }

    public void setSubstanceRepository(SubstanceRepository substanceRepository) {
        this.substanceRepository = substanceRepository;
    }

    @Override
    public ServiceOutputParameter doService(ServiceInputParameter sip) {

        // 入力パラメータからサブスタンスDTOを取得する
        SubstanceDto substanceDto = ((SipUpdateSubstanceService) sip)
                .getSubstanceDto();

        // サービスを実行する
        doService(substanceDto);

        // サービス出力パラメータを作成する
        SopUpdateSubstanceService sop = new SopUpdateSubstanceService();

        // 出力パラメータを作成し、呼び出し側に戻す
        return sop;
    }

    /*
     * (非 Javadoc)
     *
     * @see service.UpdateSubstanceService#doService(dto.SubstanceDto)
     */
    @Override
    public void doService(SubstanceDto substanceDto) {

        // DTOからエンティティへの詰め替えを行う
        Substance substance = new Substance();
        CopyUtil.copy(substanceDto, substance);

        // ドメインを取得する
        SubstanceDomain domain = substanceRepository.getDomain(substanceDto
                .getSubstanceId());

        // ドメインの更新処理を呼び出す
        domain.update(substance);
    }
}

0 件のコメント:

コメントを投稿