use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project midpoint by Evolveum.
the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.
/**
* We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
*
* We also check the metadata.channel migration for both the object and the assignment (MID-6547).
*/
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(dummyResource);
// This explicitly parses the schema, therefore ...
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 1);
ResourceObjectTypeDefinition accountDefinition = refinedSchema.findObjectTypeDefinitionRequired(ShadowKindType.ACCOUNT, null);
PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new ItemName("http://midpoint.evolveum.com/xml/ns/public/resource/instance-3", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
assertNotNull("gossip attribute definition not found", gossipDefinition);
ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
radt.setRef(new ItemPathType(gossipDefinition.getItemName()));
MappingType outbound = new MappingType();
radt.setOutbound(outbound);
ExpressionType expression = new ExpressionType();
outbound.setExpression(expression);
MappingType value = new MappingType();
// noinspection unchecked
PrismProperty<String> property = gossipDefinition.instantiate();
property.addRealValue("q");
List evaluators = expression.getExpressionEvaluator();
Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property);
ObjectFactory of = new ObjectFactory();
for (JAXBElement<RawType> obj : collection) {
// noinspection unchecked
evaluators.add(of.createValue(obj.getValue()));
}
value.setExpression(expression);
radt.setOutbound(value);
accountConstruction.getAttribute().add(radt);
PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
deltas.add(accountAssignmentUserDelta);
// Set user and assignment create channel to legacy value.
repositoryService.modifyObject(UserType.class, jackBefore.getOid(), deltaFor(UserType.class).item(UserType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).item(UserType.F_ASSIGNMENT, assignmentId, AssignmentType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).asItemDeltas(), result);
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
display("User before change execution", userJackOld);
display("Deltas to execute execution", deltas);
when();
modelService.executeChanges(deltas, null, task, result);
then();
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
// First fetch: initial account read
// Second fetch: fetchback after modification to correctly process inbound
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 2);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
accountJackOid = getSingleLinkOid(userJack);
// MID-6547 (channel URI migration)
assertThat(userJack.asObjectable().getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
assertThat(userJack.asObjectable().getAssignment().get(0).getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, SelectorOptions.createCollection(GetOperationOptions.createRaw()), result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
// Check account in dummy resource
assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
display(dummyAccount.debugDump());
assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
assertDummyScriptsModify(userJack, true);
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
assertCounterIncrement(InternalCounters.SCRIPT_COMPILE_COUNT, 0);
assertSteadyResources();
}
use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetFull.
@Ignore
@Test
public void testMarshalRecordCollectionGetFull() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.FULL);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.FULL);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.FULL));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionFullXml.
@Ignore
@Test
public void testMarshalRecordCollectionFullXml() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
TransformerManager mockMetacardManager = mock(TransformerManager.class);
when(mockMetacardManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(CswRecordConverterTest.getCswMetacardType()));
GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(new CswTransformProvider(mockMetacardManager, null));
XStream xstream = createXstream(new StaxDriver(new NoNameCoder()));
xstream.registerConverter(rrConverter);
xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.GET_RECORDS_RESPONSE, CswRecordCollection.class);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.FULL);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.FULL);
String xml = xstream.toXML(collection);
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetSummary.
@Ignore
@Test
public void testMarshalRecordCollectionGetSummary() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.SUMMARY);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.SUMMARY);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.SUMMARY));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.SUMMARY));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of net.opengis.cat.csw.v_2_0_2.ObjectFactory in project ddf by codice.
the class WfsSource method buildSortBy.
private SortByType buildSortBy(QName featureType, SortBy incomingSortBy) {
net.opengis.filter.v_1_1_0.ObjectFactory filterObjectFactory = new net.opengis.filter.v_1_1_0.ObjectFactory();
String propertyName = mapSortByPropertyName(featureType, incomingSortBy.getPropertyName().getPropertyName(), metacardMappers);
if (propertyName != null) {
SortOrder sortOrder = incomingSortBy.getSortOrder();
SortPropertyType sortPropertyType = filterObjectFactory.createSortPropertyType();
PropertyNameType propertyNameType = filterObjectFactory.createPropertyNameType();
List<Serializable> props = Arrays.asList(propertyName);
propertyNameType.setContent(props);
sortPropertyType.setPropertyName(propertyNameType);
if (SortOrder.ASCENDING.equals(sortOrder)) {
sortPropertyType.setSortOrder(SortOrderType.ASC);
} else if (SortOrder.DESCENDING.equals(sortOrder)) {
sortPropertyType.setSortOrder(SortOrderType.DESC);
} else {
LOGGER.debug("Unable to build query. Unknown sort order of [{}].", sortOrder == null ? null : sortOrder.identifier());
return null;
}
SortByType sortByType = filterObjectFactory.createSortByType();
sortByType.getSortProperty().add(sortPropertyType);
return sortByType;
}
return null;
}
Aggregations