Search in sources :

Example 11 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project ddf by codice.

the class TestCswEndpoint method testGetCapabilitiesTypeFederatedCatalogs.

@Test
public void testGetCapabilitiesTypeFederatedCatalogs() {
    GetCapabilitiesType gct = createDefaultGetCapabilitiesType();
    CapabilitiesType ct = null;
    try {
        ct = csw.getCapabilities(gct);
    } catch (CswException e) {
        fail("CswException caught during getCapabilities GET request: " + e.getMessage());
    }
    assertThat(ct, notNullValue());
    assertThat(ct.getOperationsMetadata(), notNullValue());
    for (Operation operation : ct.getOperationsMetadata().getOperation()) {
        if (StringUtils.equals(operation.getName(), CswConstants.GET_RECORDS)) {
            for (DomainType constraint : operation.getConstraint()) {
                if (StringUtils.equals(constraint.getName(), CswConstants.FEDERATED_CATALOGS)) {
                    assertThat(constraint.getValue().size(), is(3));
                    return;
                }
            }
        }
    }
    fail("Didn't find [" + CswConstants.FEDERATED_CATALOGS + "] in request [" + CswConstants.GET_RECORDS + "]");
}
Also used : DomainType(net.opengis.ows.v_1_0_0.DomainType) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Operation(net.opengis.ows.v_1_0_0.Operation) Test(org.junit.Test)

Example 12 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project oxTrust by GluuFederation.

the class BulkWebService method processBulkOperations.

@POST
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Bulk Operations", notes = "Bulk Operations (https://tools.ietf.org/html/rfc7644#section-3.7)", response = BulkResponse.class)
public Response processBulkOperations(// @Context HttpServletResponse response,
@HeaderParam("Authorization") String authorization, @HeaderParam("Content-Length") int contentLength, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "BulkRequest", required = true) BulkRequest bulkRequest) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        /*
			 * J2EContext context = new J2EContext(request, response); int
			 * removePathLength = "/Bulk".length(); String domain =
			 * context.getFullRequestURL(); if (domain.endsWith("/")) {
			 * removePathLength++; } domain = domain.substring(0,
			 * domain.length() - removePathLength);
			 */
        log.info("##### Operation count = " + bulkRequest.getOperations().size());
        log.info("##### Content-Length = " + contentLength);
        if (bulkRequest.getOperations().size() > MAX_BULK_OPERATIONS || contentLength > MAX_BULK_PAYLOAD_SIZE) {
            StringBuilder message = new StringBuilder("The size of the bulk operation exceeds the ");
            if (bulkRequest.getOperations().size() > MAX_BULK_OPERATIONS && contentLength <= MAX_BULK_PAYLOAD_SIZE) {
                message.append("maxOperations (").append(MAX_BULK_OPERATIONS).append(")");
            } else if (bulkRequest.getOperations().size() <= MAX_BULK_OPERATIONS && contentLength > MAX_BULK_PAYLOAD_SIZE) {
                message.append("maxPayloadSize (").append(MAX_BULK_PAYLOAD_SIZE).append(")");
            } else if (bulkRequest.getOperations().size() > MAX_BULK_OPERATIONS && contentLength > MAX_BULK_PAYLOAD_SIZE) {
                message.append("maxOperations (").append(MAX_BULK_OPERATIONS).append(") ");
                message.append("and ");
                message.append("maxPayloadSize (").append(MAX_BULK_PAYLOAD_SIZE).append(")");
            }
            log.info("Payload Too Large: " + message.toString());
            return getErrorResponse(413, message.toString());
        }
        int failOnErrorsLimit = (bulkRequest.getFailOnErrors() != null) ? bulkRequest.getFailOnErrors() : 0;
        int failOnErrorsCount = 0;
        List<BulkOperation> bulkOperations = bulkRequest.getOperations();
        BulkResponse bulkResponse = new BulkResponse();
        Map<String, String> processedBulkIds = new LinkedHashMap<String, String>();
        operationsLoop: for (BulkOperation operation : bulkOperations) {
            log.info(" Checking operations... ");
            if (operation.getPath().startsWith("/Users")) {
                // operation = processUserOperation(operation, domain);
                operation = processUserOperation(operation, processedBulkIds);
            } else if (operation.getPath().startsWith("/Groups")) {
                // operation = processGroupOperation(operation, domain);
                operation = processGroupOperation(operation, processedBulkIds);
            }
            bulkResponse.getOperations().add(operation);
            // Error handling
            String okCode = String.valueOf(Response.Status.OK.getStatusCode());
            String createdCode = String.valueOf(Response.Status.CREATED.getStatusCode());
            if (!operation.getStatus().equalsIgnoreCase(okCode) && !operation.getStatus().equalsIgnoreCase(createdCode)) {
                failOnErrorsCount++;
                if ((failOnErrorsLimit > 0) && (failOnErrorsCount >= failOnErrorsLimit)) {
                    break operationsLoop;
                }
            }
        }
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Bulk");
        // Serialize to JSON
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        SimpleModule customBulkOperationsModule = new SimpleModule("CustomBulkOperationsModule", new Version(1, 0, 0, ""));
        // Custom serializers for both User and Group
        ListResponseUserSerializer userSerializer = new ListResponseUserSerializer();
        ListResponseGroupSerializer groupSerializer = new ListResponseGroupSerializer();
        customBulkOperationsModule.addSerializer(User.class, userSerializer);
        customBulkOperationsModule.addSerializer(Group.class, groupSerializer);
        mapper.registerModule(customBulkOperationsModule);
        String json = mapper.writeValueAsString(bulkResponse);
        return Response.ok(json).location(location).build();
    } catch (Exception ex) {
        log.error("Error in processBulkOperations", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : ListResponseUserSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.ListResponseUserSerializer) BulkOperation(org.gluu.oxtrust.model.scim2.BulkOperation) BulkResponse(org.gluu.oxtrust.model.scim2.BulkResponse) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) LinkedHashMap(java.util.LinkedHashMap) Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.BulkResponse) ErrorResponse(org.gluu.oxtrust.model.scim2.ErrorResponse) Version(org.codehaus.jackson.Version) ListResponseGroupSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.ListResponseGroupSerializer) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 13 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project oxTrust by GluuFederation.

the class Scim2UserService method addUserPatch.

private void addUserPatch(Operation operation, String id) throws Exception {
    User user = operation.getValue();
    GluuCustomPerson updatedGluuPerson = patchUtil.addPatch(user, validUsernameByInum(user, id));
    log.info(" Setting meta: addUserPatch update user ");
    setMeta(updatedGluuPerson);
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser)

Example 14 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project ddf by codice.

the class TestCswSourceBase method configureMockCsw.

protected void configureMockCsw(int numRecordsReturned, long numRecordsMatched, String cswVersion) throws CswException {
    ServiceIdentification mockServiceIdentification = mock(ServiceIdentification.class);
    when(mockServiceIdentification.getAbstract()).thenReturn("myDescription");
    CapabilitiesType mockCapabilities = mock(CapabilitiesType.class);
    when(mockCapabilities.getVersion()).thenReturn(cswVersion);
    when(mockCapabilities.getServiceIdentification()).thenReturn(mockServiceIdentification);
    when(mockCapabilities.getServiceIdentification()).thenReturn(mockServiceIdentification);
    when(mockCsw.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
    FilterCapabilities mockFilterCapabilities = mock(FilterCapabilities.class);
    when(mockCapabilities.getFilterCapabilities()).thenReturn(mockFilterCapabilities);
    List<ComparisonOperatorType> comparisonOpsList = new ArrayList<>();
    comparisonOpsList.add(ComparisonOperatorType.EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.LIKE);
    comparisonOpsList.add(ComparisonOperatorType.NOT_EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.GREATER_THAN);
    comparisonOpsList.add(ComparisonOperatorType.GREATER_THAN_EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.LESS_THAN);
    comparisonOpsList.add(ComparisonOperatorType.LESS_THAN_EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.BETWEEN);
    comparisonOpsList.add(ComparisonOperatorType.NULL_CHECK);
    ComparisonOperatorsType comparisonOps = new ComparisonOperatorsType();
    comparisonOps.setComparisonOperator(comparisonOpsList);
    ScalarCapabilitiesType mockScalarCapabilities = mock(ScalarCapabilitiesType.class);
    when(mockScalarCapabilities.getLogicalOperators()).thenReturn(mock(LogicalOperators.class));
    mockScalarCapabilities.setComparisonOperators(comparisonOps);
    when(mockScalarCapabilities.getComparisonOperators()).thenReturn(comparisonOps);
    when(mockFilterCapabilities.getScalarCapabilities()).thenReturn(mockScalarCapabilities);
    List<DomainType> getRecordsParameters = new ArrayList<>();
    DomainType typeName = new DomainType();
    typeName.setName(CswConstants.TYPE_NAME_PARAMETER);
    typeName.setValue(Collections.singletonList("csw:Record"));
    getRecordsParameters.add(typeName);
    DomainType typeNames = new DomainType();
    typeNames.setName(CswConstants.TYPE_NAMES_PARAMETER);
    getRecordsParameters.add(typeNames);
    DomainType getRecordsOutputSchema = new DomainType();
    getRecordsOutputSchema.setName(CswConstants.OUTPUT_SCHEMA_PARAMETER);
    getRecordsOutputSchema.getValue().add(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordsParameters.add(getRecordsOutputSchema);
    DomainType constraintLang = new DomainType();
    constraintLang.setName(CswConstants.CONSTRAINT_LANGUAGE_PARAMETER);
    constraintLang.setValue(Collections.singletonList(CswConstants.CONSTRAINT_LANGUAGE_FILTER));
    getRecordsParameters.add(constraintLang);
    DomainType outputFormat = new DomainType();
    outputFormat.setName(CswConstants.OUTPUT_FORMAT_PARAMETER);
    getRecordsParameters.add(outputFormat);
    DomainType resultType = new DomainType();
    resultType.setName(CswConstants.RESULT_TYPE_PARAMETER);
    getRecordsParameters.add(resultType);
    DomainType elementSetName = new DomainType();
    elementSetName.setName(CswConstants.ELEMENT_SET_NAME_PARAMETER);
    getRecordsParameters.add(elementSetName);
    List<DomainType> getRecordByIdParameters = new ArrayList<>();
    DomainType getRecordByIdOutputSchema = new DomainType();
    getRecordByIdOutputSchema.setName(CswConstants.OUTPUT_SCHEMA_PARAMETER);
    List<String> outputSchemas = new ArrayList<>();
    outputSchemas.add(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordByIdOutputSchema.setValue(outputSchemas);
    getRecordByIdParameters.add(getRecordByIdOutputSchema);
    Operation getRecords = new Operation();
    getRecords.setName(CswConstants.GET_RECORDS);
    getRecords.setParameter(getRecordsParameters);
    Operation getRecordById = new Operation();
    getRecordById.setName(CswConstants.GET_RECORD_BY_ID);
    getRecordById.setParameter(getRecordByIdParameters);
    List<Operation> operations = new ArrayList<>(2);
    operations.add(getRecords);
    operations.add(getRecordById);
    OperationsMetadata mockOperationsMetadata = mock(OperationsMetadata.class);
    mockOperationsMetadata.setOperation(operations);
    when(mockCapabilities.getOperationsMetadata()).thenReturn(mockOperationsMetadata);
    when(mockOperationsMetadata.getOperation()).thenReturn(operations);
    if (numRecordsReturned > 0) {
        List<Metacard> metacards = new ArrayList<>(numRecordsReturned);
        for (int i = 1; i <= numRecordsReturned; i++) {
            String id = "ID_" + String.valueOf(i);
            MetacardImpl metacard = new MetacardImpl();
            metacard.setId(id);
            metacard.setContentTypeName("myContentType");
            metacards.add(metacard);
        }
        SearchResultsType searchResults = mock(SearchResultsType.class);
        when(searchResults.getNumberOfRecordsMatched()).thenReturn(BigInteger.valueOf(numRecordsMatched));
        when(searchResults.getNumberOfRecordsReturned()).thenReturn(BigInteger.valueOf(numRecordsReturned));
        CswRecordCollection mockCswRecordCollection = mock(CswRecordCollection.class);
        when(mockCswRecordCollection.getCswRecords()).thenReturn(metacards);
        when(mockCswRecordCollection.getNumberOfRecordsMatched()).thenReturn(numRecordsMatched);
        when(mockCswRecordCollection.getNumberOfRecordsReturned()).thenReturn((long) numRecordsReturned);
        when(mockCsw.getRecords(any(GetRecordsType.class))).thenReturn(mockCswRecordCollection);
    }
}
Also used : GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) OperationsMetadata(net.opengis.ows.v_1_0_0.OperationsMetadata) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) ArrayList(java.util.ArrayList) LogicalOperators(net.opengis.filter.v_1_1_0.LogicalOperators) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) Operation(net.opengis.ows.v_1_0_0.Operation) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) ComparisonOperatorsType(net.opengis.filter.v_1_1_0.ComparisonOperatorsType) Metacard(ddf.catalog.data.Metacard) DomainType(net.opengis.ows.v_1_0_0.DomainType) ScalarCapabilitiesType(net.opengis.filter.v_1_1_0.ScalarCapabilitiesType) ScalarCapabilitiesType(net.opengis.filter.v_1_1_0.ScalarCapabilitiesType) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ComparisonOperatorType(net.opengis.filter.v_1_1_0.ComparisonOperatorType) ServiceIdentification(net.opengis.ows.v_1_0_0.ServiceIdentification)

Example 15 with Operation

use of org.gluu.oxtrust.model.scim2.Operation in project ddf by codice.

the class CswEndpoint method buildOperation.

/**
     * Creates an Operation object for the OperationsMetadata section TODO: We currently don't use
     * the constraint or metadata elements, those can be added in as desired
     *
     * @param name  The name of the operation
     * @param types The request types supported (GET/POST)
     * @return The constructed Operation object
     */
private Operation buildOperation(String name, List<QName> types) {
    Operation op = new Operation();
    op.setName(name);
    ArrayList<DCP> dcpList = new ArrayList<>();
    DCP dcp = new DCP();
    HTTP http = new HTTP();
    for (QName type : types) {
        RequestMethodType rmt = new RequestMethodType();
        rmt.setHref(uri.getBaseUri().toASCIIString());
        JAXBElement<RequestMethodType> requestElement = new JAXBElement<>(type, RequestMethodType.class, rmt);
        if (type.equals(CswConstants.POST)) {
            requestElement.getValue().getConstraint().add(createDomainType(CswConstants.POST_ENCODING, CswConstants.XML));
        }
        http.getGetOrPost().add(requestElement);
    }
    dcp.setHTTP(http);
    dcpList.add(dcp);
    op.setDCP(dcpList);
    return op;
}
Also used : DCP(net.opengis.ows.v_1_0_0.DCP) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) HTTP(net.opengis.ows.v_1_0_0.HTTP) Operation(net.opengis.ows.v_1_0_0.Operation) JAXBElement(javax.xml.bind.JAXBElement) RequestMethodType(net.opengis.ows.v_1_0_0.RequestMethodType)

Aggregations

Operation (net.opengis.ows.v_1_0_0.Operation)10 DomainType (net.opengis.ows.v_1_0_0.DomainType)8 ArrayList (java.util.ArrayList)7 OperationsMetadata (net.opengis.ows.v_1_0_0.OperationsMetadata)5 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)5 User (org.gluu.oxtrust.model.scim2.User)4 LinkedHashMap (java.util.LinkedHashMap)3 CapabilitiesType (net.opengis.cat.csw.v_2_0_2.CapabilitiesType)3 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)3 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)3 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 GetCapabilitiesType (net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType)2 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)2 GetCapabilitiesRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest)2 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)2 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 Metacard (ddf.catalog.data.Metacard)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1