ee.datel.client.kr.LihtandmedService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xtee6-client-kr Show documentation
Show all versions of xtee6-client-kr Show documentation
Library for XROAD KR service clints
The newest version!
package ee.datel.client.kr;
/*-
* ==========================LICENSE_START===================================
* ee.datel.xtee6:xtee6-client-kr
*
* Copyright (C) 2018 - 2024 AS Datel
*
* Redistribution and use in binary form, without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 2. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ===========================LICENSE_END====================================
*/
import ee.datel.client.utils.ServiceUtils;
import ee.datel.xtee.fault.ServiceFaultException;
import ee.xtee6.kr.liht.ArrayOfKinnistuRegistriosa;
import ee.xtee6.kr.liht.ArrayOfOmand;
import ee.xtee6.kr.liht.Client;
import ee.xtee6.kr.liht.IKr;
import ee.xtee6.kr.liht.KinnistuLihtandmedRequest;
import ee.xtee6.kr.liht.KinnistuRegistriosa;
import ee.xtee6.kr.liht.Kr;
import ee.xtee6.kr.liht.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import jakarta.xml.ws.Holder;
import jakarta.xml.ws.WebServiceException;
public class LihtandmedService extends KrCommon {
private static Kr srv = new Kr();
private LihtandmedService() {}
public static List getKinnistudOmanikul(LihtandmedXRoadParams params, String userid,
String isik, String roNumber, String kyTunnus) throws ServiceFaultException {
KinnistuLihtandmedRequest request = new KinnistuLihtandmedRequest();
request.setKinnistuKehtivus("1");
request.setKasKehtetuOmanik("0");
request.setKasOigustatudIsik("0");
request.setKood(Objects.requireNonNull(isik, "Puudub isikukood"));
request.setKoodRiik("EST");
if (roNumber != null) {
request.setKinnistuNumber(roNumber);
}
if (kyTunnus != null) {
request.setKatastritunnus(kyTunnus);
}
List result = new ArrayList<>();
collectKinnistud(params, userid, request, result, 1);
return result;
}
public static List getKinnistudKatasriyksusel(LihtandmedXRoadParams params, String userid,
String katastritunnus) throws ServiceFaultException {
return doKinnistudKatasriyksusel(params, userid, katastritunnus, "1");
}
public static List getKinnistudKatasriyksuselAjalugu(LihtandmedXRoadParams params,
String userid, String katastritunnus) throws ServiceFaultException {
return doKinnistudKatasriyksusel(params, userid, katastritunnus, "0");
}
private static List doKinnistudKatasriyksusel(LihtandmedXRoadParams params, String userid,
String katastritunnus, String kehtiv) throws ServiceFaultException {
KinnistuLihtandmedRequest request = new KinnistuLihtandmedRequest();
request.setKinnistuKehtivus(kehtiv);
request.setKatastritunnus(katastritunnus);
List result = new ArrayList<>();
collectKinnistud(params, userid, request, result, 1);
return result;
}
private static void collectKinnistud(LihtandmedXRoadParams params, String userid, KinnistuLihtandmedRequest request,
List result, int pageNr) throws ServiceFaultException {
request.setLehekyljeNr(pageNr);
Holder kirjeteArvKokku = new Holder<>();
Holder kirjeteArvParingus = new Holder<>();
Holder lehekyljeNr = new Holder<>();
Holder omandid = new Holder<>();
Holder registriosad = new Holder<>();
Holder kood = new Holder<>();
Holder teade = new Holder<>();
var id = ServiceUtils.getRequestId();
try {
params.getPort().kinnistuLihtandmed(request, kirjeteArvKokku, kirjeteArvParingus, kood, lehekyljeNr,
omandid, registriosad, teade, params.getClient(), params.getService(), userid, id,
ServiceUtils.getProtocolVersion());
} catch (WebServiceException ex) {
throw new ServiceFaultException(ex.getClass().getSimpleName(), ex.getMessage(), id);
}
if (kood.value > 1) {
throw new ServiceFaultException(kood.value.toString(), teade.value, id);
}
result.addAll(registriosad.value.getKinnistuRegistriosas());
while (result.size() < kirjeteArvKokku.value) {
collectKinnistud(params, userid, request, result, pageNr + 1);
}
}
public static KinnistuRegistriosa getKinnistuAndmed(LihtandmedXRoadParams params, String userid, String roNumber)
throws ServiceFaultException {
KinnistuLihtandmedRequest request = new KinnistuLihtandmedRequest();
request.setKinnistuKehtivus("1");
request.setKinnistuNumber(roNumber);
Holder kirjeteArvKokku = new Holder<>();
Holder kirjeteArvParingus = new Holder<>();
Holder lehekyljeNr = new Holder<>();
Holder omandid = new Holder<>();
Holder registriosad = new Holder<>();
Holder kood = new Holder<>();
Holder teade = new Holder<>();
var id = ServiceUtils.getRequestId();
try {
params.getPort().kinnistuLihtandmed(request, kirjeteArvKokku, kirjeteArvParingus, kood, lehekyljeNr,
omandid, registriosad, teade, params.getClient(), params.getService(), userid, id,
ServiceUtils.getProtocolVersion());
} catch (WebServiceException ex) {
throw new ServiceFaultException(ex.getClass().getSimpleName(), ex.getMessage(), id);
}
if (kood.value > 1) {
throw new ServiceFaultException(kood.value.toString(), teade.value, id);
}
return kirjeteArvKokku.value > 0 ? registriosad.value.getKinnistuRegistriosas().get(0) : null;
}
protected static Service getServiceIdentifier(String xroadInstance) {
return getServiceIdentifier(xroadInstance, memberClass, serviceCode, subsystemCode, "Kinnistu_Lihtandmed",
null);
}
protected static IKr getServicePort(String serverUrl) {
IKr port = srv.getBasicHttpBindingIKr();
ServiceUtils.connectPort(port, serverUrl);
return port;
}
protected static Client getClientIdentifier(String xroadInstance, String memberClass, String memberCode,
String subsystemCode) {
var client = new Client();
ServiceUtils.getXRoadIdentifierType(client, xroadInstance, memberClass, memberCode, subsystemCode);
return client;
}
protected static Service getServiceIdentifier(String xroadInstance, String memberClass, String memberCode,
String subsystemCode, String serviceCode, String serviceVersion) {
var server = new Service();
ServiceUtils.getXRoadIdentifierType(server, xroadInstance, memberClass, memberCode, subsystemCode, serviceCode,
serviceVersion);
return server;
}
public static class LihtandmedXRoadParams {
private IKr port;
private Client client;
private Service service;
public LihtandmedXRoadParams(String serverUrl, String xRoadInstance, String memberClass, String memberCode,
String subsystemCode) {
port = getServicePort(serverUrl);
client = getClientIdentifier(xRoadInstance, memberClass, memberCode, subsystemCode);
service = getServiceIdentifier(xRoadInstance);
}
public Service getService() {
return service;
}
public Client getClient() {
return client;
}
public IKr getPort() {
return port;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy