Search in sources :

Example 1 with TrustContact

use of org.xdi.model.TrustContact in project oxTrust by GluuFederation.

the class TrustRelationshipWebService method setContacts.

@POST
@Path("/set_contacts/{inum}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "set contacts for TrustRelationship", notes = "Find TrustRelationship by inum and set contacts. Contacts parameter is List<TrustContact>")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Server error") })
public void setContacts(@PathParam("inum") String trustRelationshipInum, String contacts, @Context HttpServletResponse response) {
    try {
        GluuSAMLTrustRelationship trustRelationship = trustService.getRelationshipByInum(trustRelationshipInum);
        List<TrustContact> contactsList = objectMapper.readValue(contacts, new TypeReference<List<TrustContact>>() {
        });
        trustService.saveContacts(trustRelationship, contactsList);
    } catch (Exception e) {
        logger.error("setContacts() Exception", e);
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR");
        } catch (Exception ex) {
        }
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) TrustContact(org.xdi.model.TrustContact) List(java.util.List) ArrayList(java.util.ArrayList) CertificateEncodingException(java.security.cert.CertificateEncodingException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 2 with TrustContact

use of org.xdi.model.TrustContact in project oxTrust by GluuFederation.

the class TrustContactsAction method removeEmptyContacts.

private void removeEmptyContacts() {
    TrustContact emptyContact = new TrustContact();
    emptyContact.setMail("");
    emptyContact.setName("");
    emptyContact.setPhone("");
    emptyContact.setTitle("");
    List<TrustContact> trustContacts = new ArrayList<TrustContact>(contacts);
    for (TrustContact contact : trustContacts) {
        if (contact.equals(emptyContact)) {
            contacts.remove(contact);
        }
    }
}
Also used : TrustContact(org.xdi.model.TrustContact) ArrayList(java.util.ArrayList)

Example 3 with TrustContact

use of org.xdi.model.TrustContact in project oxTrust by GluuFederation.

the class TrustService method saveContacts.

public void saveContacts(GluuSAMLTrustRelationship trustRelationship, List<TrustContact> contacts) {
    if (contacts != null && !contacts.isEmpty()) {
        List<String> gluuTrustContacts = new ArrayList<String>();
        for (TrustContact contact : contacts) {
            gluuTrustContacts.add(xmlService.getXMLFromTrustContact(contact));
        }
        trustRelationship.setGluuTrustContact(gluuTrustContacts);
    }
}
Also used : TrustContact(org.xdi.model.TrustContact) ArrayList(java.util.ArrayList)

Example 4 with TrustContact

use of org.xdi.model.TrustContact in project oxTrust by GluuFederation.

the class TrustRelationshipWebService method getContacts.

@GET
@Path("/get_contacts/{inum}")
@Produces(MediaType.TEXT_PLAIN)
public String getContacts(@PathParam("inum") String trustRelationshipInum, @Context HttpServletResponse response) {
    try {
        GluuSAMLTrustRelationship trustRelationship = trustService.getRelationshipByInum(trustRelationshipInum);
        List<TrustContact> list = trustService.getContacts(trustRelationship);
        // convert to JSON
        return objectMapper.writeValueAsString(list);
    } catch (Exception e) {
        logger.error("getContacts() Exception", e);
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR");
        } catch (Exception ex) {
        }
        return OxTrustConstants.RESULT_FAILURE;
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) TrustContact(org.xdi.model.TrustContact) CertificateEncodingException(java.security.cert.CertificateEncodingException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

TrustContact (org.xdi.model.TrustContact)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)2 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)1 List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1