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 + "]");
}
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);
}
}
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);
}
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);
}
}
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;
}
Aggregations