001/*
002 * *** BEGIN LICENSE BLOCK *****
003 *  Version: MPL 1.1/GPL 2.0/LGPL 2.1
004 *
005 *  The contents of this file are subject to the Mozilla Public License Version
006 *  1.1 (the "License"); you may not use this file except in compliance with
007 *  the License. You may obtain a copy of the License at
008 *  http://www.mozilla.org/MPL/
009 *
010 *  Software distributed under the License is distributed on an "AS IS" basis,
011 *  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
012 *  for the specific language governing rights and limitations under the
013 *  License.
014 *
015 *  The Original Code is part of dcm4che, an implementation of DICOM(TM) in
016 *  Java(TM), hosted at https://github.com/gunterze/dcm4che.
017 *
018 *  The Initial Developer of the Original Code is
019 *  Agfa Healthcare.
020 *  Portions created by the Initial Developer are Copyright (C) 2015
021 *  the Initial Developer. All Rights Reserved.
022 *
023 *  Contributor(s):
024 *  See @authors listed below
025 *
026 *  Alternatively, the contents of this file may be used under the terms of
027 *  either the GNU General Public License Version 2 or later (the "GPL"), or
028 *  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
029 *  in which case the provisions of the GPL or the LGPL are applicable instead
030 *  of those above. If you wish to allow use of your version of this file only
031 *  under the terms of either the GPL or the LGPL, and not to allow others to
032 *  use your version of this file under the terms of the MPL, indicate your
033 *  decision by deleting the provisions above and replace them with the notice
034 *  and other provisions required by the GPL or the LGPL. If you do not delete
035 *  the provisions above, a recipient may use your version of this file under
036 *  the terms of any one of the MPL, the GPL or the LGPL.
037 *
038 *  ***** END LICENSE BLOCK *****
039 */
040
041package org.dcm4che3.net.service;
042
043import java.io.IOException;
044
045import org.dcm4che3.data.Attributes;
046import org.dcm4che3.data.UID;
047import org.dcm4che3.net.Association;
048import org.dcm4che3.net.Commands;
049import org.dcm4che3.net.Dimse;
050import org.dcm4che3.net.Status;
051import org.dcm4che3.net.pdu.PresentationContext;
052
053/**
054 * Base Service Class Provider (SCP) for the Instance Available Notification (IAN) SOP Class.
055 *
056 * @author Hermann Czedik-Eysenberg <hermann-agfa@czedik.net>
057 */
058public class BasicIanSCP extends AbstractDicomService {
059
060    public BasicIanSCP() {
061        super(UID.InstanceAvailabilityNotificationSOPClass);
062    }
063
064    @Override
065    public void onDimseRQ(Association as, PresentationContext pc,
066                          Dimse dimse, Attributes cmd, Attributes data)
067            throws IOException {
068        if (dimse != Dimse.N_CREATE_RQ)
069            throw new DicomServiceException(Status.UnrecognizedOperation);
070        onNCreateRQ(as, pc, cmd, data);
071    }
072
073    protected void onNCreateRQ(Association as, PresentationContext pc, Attributes cmd, Attributes data) throws IOException {
074        Attributes rsp = Commands.mkNCreateRSP(cmd, getDefaultResponseStatus());
075        Attributes rspAttrs = create(as, cmd, data);
076        as.tryWriteDimseRSP(pc, rsp, rspAttrs);
077    }
078
079    protected int getDefaultResponseStatus() {
080        return Status.Success;
081    }
082
083    protected Attributes create(Association as, Attributes cmd, Attributes data) throws DicomServiceException {
084        return null;
085    }
086
087}