Search in sources :

Example 1 with GetCardInfoOrACDResponse

use of iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse in project open-ecard by ecsec.

the class CardRecognitionImpl method getCardInfoFromRepo.

@Override
public CardInfoType getCardInfoFromRepo(String type) {
    CardInfoType cif = null;
    // only do something when a repo is specified
    if (cif == null && cifRepo != null) {
        GetCardInfoOrACD req = new GetCardInfoOrACD();
        req.setAction(ECardConstants.CIF.GET_SPECIFIED);
        req.getCardTypeIdentifier().add(type);
        GetCardInfoOrACDResponse res = getCifRepo().getCardInfoOrACD(req);
        // checkout response if it contains our cardinfo
        List<Serializable> cifs = res.getCardInfoOrCapabilityInfo();
        for (Serializable next : cifs) {
            if (next instanceof CardInfoType) {
                return (CardInfoType) next;
            }
        }
    }
    return cif;
}
Also used : Serializable(java.io.Serializable) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) GetCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)

Example 2 with GetCardInfoOrACDResponse

use of iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse in project open-ecard by ecsec.

the class CardRecognitionImpl method getCardInfos.

@Override
public List<CardInfoType> getCardInfos() {
    // TODO: add caching
    GetCardInfoOrACD req = new GetCardInfoOrACD();
    req.setAction(ECardConstants.CIF.GET_OTHER);
    GetCardInfoOrACDResponse res = getCifRepo().getCardInfoOrACD(req);
    // checkout response if it contains our cardinfo
    List<Serializable> cifs = res.getCardInfoOrCapabilityInfo();
    ArrayList<CardInfoType> result = new ArrayList<>();
    for (Serializable next : cifs) {
        if (next instanceof CardInfoType) {
            result.add((CardInfoType) next);
        }
    }
    return result;
}
Also used : Serializable(java.io.Serializable) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) GetCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD) ArrayList(java.util.ArrayList) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)

Example 3 with GetCardInfoOrACDResponse

use of iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse in project open-ecard by ecsec.

the class LocalCifRepo method getCardInfoOrACD.

@Override
public GetCardInfoOrACDResponse getCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD parameters) {
    List<String> cardTypes = parameters.getCardTypeIdentifier();
    ArrayList<CardInfoType> cifsResult = new ArrayList<>(cardTypes.size());
    Result result = WSHelper.makeResultOK();
    try {
        if (ECardConstants.CIF.GET_SPECIFIED.equals(parameters.getAction())) {
            ArrayList<String> missingTypes = new ArrayList<>();
            for (String cardType : cardTypes) {
                Document cif = cifs.get(cardType);
                if (cif == null) {
                    missingTypes.add(cardType);
                } else {
                    // marshal here to receive a copy of the CIF
                    cifsResult.add((CardInfoType) m.unmarshal(cif));
                }
            }
            if (!missingTypes.isEmpty()) {
                StringBuilder error = new StringBuilder("The following card types could not be found:");
                for (String type : missingTypes) {
                    error.append("\n  ").append(type);
                }
                result = WSHelper.makeResultError(ECardConstants.Minor.SAL.UNKNOWN_CARDTYPE, error.toString());
            }
        } else if (ECardConstants.CIF.GET_OTHER.equals(parameters.getAction())) {
            HashMap<String, Document> cifsTmp = new HashMap<>();
            cifsTmp.putAll(cifs);
            for (String cardType : cardTypes) {
                cifsTmp.remove(cardType);
            }
            for (Map.Entry<String, Document> e : cifsTmp.entrySet()) {
                Document next = e.getValue();
                cifsResult.add((CardInfoType) m.unmarshal(next));
            }
        } else {
            result = WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, "Given action is unsupported.");
        }
        GetCardInfoOrACDResponse res = WSHelper.makeResponse(GetCardInfoOrACDResponse.class, result);
        res.getCardInfoOrCapabilityInfo().addAll(cifsResult);
        return res;
    } catch (WSMarshallerException ex) {
        String msg = "Failed to unmarshal a CIF document.";
        logger.error(msg, ex);
        result = WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg);
        GetCardInfoOrACDResponse res = WSHelper.makeResponse(GetCardInfoOrACDResponse.class, result);
        return res;
    }
}
Also used : WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Result(oasis.names.tc.dss._1_0.core.schema.Result) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)

Example 4 with GetCardInfoOrACDResponse

use of iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse in project open-ecard by ecsec.

the class TestLocalCif method testeGKCif.

@Test
public void testeGKCif() throws WSMarshallerException, IOException, SAXException {
    LocalCifRepo repo = new LocalCifRepo(new JAXBMarshaller());
    GetCardInfoOrACD req = new GetCardInfoOrACD();
    req.setAction(ECardConstants.CIF.GET_SPECIFIED);
    req.getCardTypeIdentifier().add("http://ws.gematik.de/egk/1.0.0");
    GetCardInfoOrACDResponse res = repo.getCardInfoOrACD(req);
    try {
        WSHelper.checkResult(res);
    } catch (WSException ex) {
        Assert.fail("Local repo returned with error\n" + ex.getMessage());
    }
    Assert.assertEquals(1, res.getCardInfoOrCapabilityInfo().size());
}
Also used : GetCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD) WSException(org.openecard.common.WSHelper.WSException) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse) LocalCifRepo(org.openecard.recognition.staticrepo.LocalCifRepo) JAXBMarshaller(org.openecard.ws.jaxb.JAXBMarshaller) Test(org.testng.annotations.Test)

Example 5 with GetCardInfoOrACDResponse

use of iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse in project open-ecard by ecsec.

the class CardRecognitionImpl method getAllTypesFromRepo.

private List<String> getAllTypesFromRepo(org.openecard.ws.GetCardInfoOrACD repo) throws WSHelper.WSException {
    // read list of all cifs from the repo
    GetCardInfoOrACD req = new GetCardInfoOrACD();
    req.setAction(ECardConstants.CIF.GET_OTHER);
    GetCardInfoOrACDResponse res = repo.getCardInfoOrACD(req);
    WSHelper.checkResult(res);
    ArrayList<String> oids = new ArrayList<>();
    for (Object cif : res.getCardInfoOrCapabilityInfo()) {
        if (cif instanceof CardInfoType) {
            String type = ((CardInfoType) cif).getCardType().getObjectIdentifier();
            oids.add(type);
        }
    }
    return oids;
}
Also used : CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) GetCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD) ArrayList(java.util.ArrayList) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)

Aggregations

GetCardInfoOrACDResponse (iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)5 CardInfoType (iso.std.iso_iec._24727.tech.schema.CardInfoType)4 GetCardInfoOrACD (iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD)4 ArrayList (java.util.ArrayList)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)1 Result (oasis.names.tc.dss._1_0.core.schema.Result)1 WSException (org.openecard.common.WSHelper.WSException)1 LocalCifRepo (org.openecard.recognition.staticrepo.LocalCifRepo)1 JAXBMarshaller (org.openecard.ws.jaxb.JAXBMarshaller)1 WSMarshallerException (org.openecard.ws.marshal.WSMarshallerException)1 Test (org.testng.annotations.Test)1 Document (org.w3c.dom.Document)1