Search in sources :

Example 56 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project BibleMultiConverter by schierlm.

the class ZefaniaXML method createXMLBible.

protected XMLBIBLE createXMLBible(Bible bible) throws Exception {
    ObjectFactory of = new ObjectFactory();
    XMLBIBLE doc = of.createXMLBIBLE();
    doc.setBiblename(bible.getName());
    doc.setType(EnumModtyp.X_BIBLE);
    doc.setINFORMATION(of.createINFORMATION());
    MetadataBook metadata = bible.getMetadataBook();
    if (metadata != null) {
        for (String key : metadata.getKeys()) {
            String value = metadata.getValue(key);
            if (key.equals(MetadataBookKey.status.toString())) {
                doc.setStatus(EnumStatus.fromValue(value));
            } else if (key.equals(MetadataBookKey.version.toString())) {
                doc.setVersion(value);
            } else if (key.equals(MetadataBookKey.revision.toString())) {
                doc.setRevision(new BigInteger(value));
            } else if (!key.contains("@")) {
                Pattern regex = INFORMATION_FIELDS.get(MetadataBookKey.valueOf(key));
                if (regex != null && regex.matcher(value).matches())
                    doc.getINFORMATION().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName(key), String.class, value));
            }
        }
    }
    doc.getINFORMATION().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName("format"), String.class, "Zefania XML Bible Markup Language"));
    for (Book bk : bible.getBooks()) {
        if (bk.getId().equals(BookID.METADATA))
            continue;
        if (bk.getId().getZefID() <= 0) {
            System.out.println("WARNING: Unable to export book " + bk.getAbbr());
            continue;
        }
        BIBLEBOOK bb = of.createBIBLEBOOK();
        bb.setBnumber(BigInteger.valueOf(bk.getId().getZefID()));
        bb.setBsname(bk.getShortName());
        bb.setBname(bk.getLongName());
        int cnumber = 0;
        for (Chapter ccc : bk.getChapters()) {
            cnumber++;
            if (ccc.getVerses().size() == 0)
                continue;
            CHAPTER cc = of.createCHAPTER();
            cc.setCnumber(BigInteger.valueOf(cnumber));
            bb.getCHAPTER().add(cc);
            if (ccc.getProlog() != null) {
                PROLOG prolog = of.createPROLOG();
                prolog.setVref(BigInteger.ONE);
                ccc.getProlog().accept(new CreateContentVisitor(of, prolog.getContent(), null));
                cc.getPROLOGOrCAPTIONOrVERS().add(prolog);
            }
            for (VirtualVerse vv : ccc.createVirtualVerses()) {
                for (Headline h : vv.getHeadlines()) {
                    CAPTION caption = of.createCAPTION();
                    caption.setVref(BigInteger.valueOf(vv.getNumber()));
                    h.accept(new CreateContentVisitor(of, caption.getContent(), null));
                    EnumCaptionType[] types = new EnumCaptionType[] { null, EnumCaptionType.X_H_1, EnumCaptionType.X_H_2, EnumCaptionType.X_H_3, EnumCaptionType.X_H_4, EnumCaptionType.X_H_5, EnumCaptionType.X_H_6, null, null, null };
                    caption.setType(types[h.getDepth()]);
                    cc.getPROLOGOrCAPTIONOrVERS().add(caption);
                }
                VERS vers = of.createVERS();
                vers.setVnumber(BigInteger.valueOf(vv.getNumber()));
                for (Verse v : vv.getVerses()) {
                    if (!v.getNumber().equals("" + vv.getNumber())) {
                        STYLE verseNum = of.createSTYLE();
                        verseNum.setCss("font-weight: bold");
                        verseNum.getContent().add("(" + v.getNumber() + ")");
                        vers.getContent().add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, verseNum));
                        vers.getContent().add(" ");
                    }
                    v.accept(new CreateContentVisitor(of, vers.getContent(), vers));
                }
                cc.getPROLOGOrCAPTIONOrVERS().add(vers);
            }
        }
        doc.getBIBLEBOOK().add(bb);
    }
    return doc;
}
Also used : MetadataBook(biblemulticonverter.data.MetadataBook) Pattern(java.util.regex.Pattern) VirtualVerse(biblemulticonverter.data.VirtualVerse) XMLBIBLE(biblemulticonverter.schema.zef2005.XMLBIBLE) QName(javax.xml.namespace.QName) Chapter(biblemulticonverter.data.Chapter) STYLE(biblemulticonverter.schema.zef2005.STYLE) BIBLEBOOK(biblemulticonverter.schema.zef2005.BIBLEBOOK) ObjectFactory(biblemulticonverter.schema.zef2005.ObjectFactory) EnumCaptionType(biblemulticonverter.schema.zef2005.EnumCaptionType) CHAPTER(biblemulticonverter.schema.zef2005.CHAPTER) Book(biblemulticonverter.data.Book) MetadataBook(biblemulticonverter.data.MetadataBook) Headline(biblemulticonverter.data.FormattedText.Headline) VERS(biblemulticonverter.schema.zef2005.VERS) BigInteger(java.math.BigInteger) PROLOG(biblemulticonverter.schema.zef2005.PROLOG) CAPTION(biblemulticonverter.schema.zef2005.CAPTION) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 57 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) List(java.util.List) ArrayList(java.util.ArrayList) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) JAXBElement(javax.xml.bind.JAXBElement) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) Test(org.testng.annotations.Test)

Example 58 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project midpoint by Evolveum.

the class TestAssignmentProcessor2 method createCondition.

private MappingType createCondition(String conditionName, char conditionType) {
    ScriptExpressionEvaluatorType script = new ScriptExpressionEvaluatorType();
    switch(conditionType) {
        case '+':
            script.setCode("basic.stringify(name) == 'jack1'");
            break;
        case '-':
            script.setCode("basic.stringify(name) == 'jack'");
            break;
        case '0':
            script.setCode("basic.stringify(name) == 'never there'");
            break;
        case '!':
            script.setCode(createDumpConditionCode(conditionName));
            break;
        default:
            throw new AssertionError(conditionType);
    }
    ExpressionType expression = new ExpressionType();
    expression.getExpressionEvaluator().add(new ObjectFactory().createScript(script));
    VariableBindingDefinitionType source = new VariableBindingDefinitionType();
    source.setPath(new ItemPathType(UserType.F_NAME));
    MappingType rv = new MappingType();
    rv.setName(conditionName);
    rv.setExpression(expression);
    rv.getSource().add(source);
    return rv;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Example 59 with ObjectFactory

use of com.evolveum.prism.xml.ns._public.query_3.ObjectFactory in project onebusaway-application-modules by camsys.

the class SpringContainer method register.

@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
    // Since we're about to override...
    builder.setAllowDuplicates(true);
    builder.factory(ObjectFactory.class, new Factory<ObjectFactory>() {

        public ObjectFactory create(Context xworkContext) throws Exception {
            SpringObjectFactory f = new SpringObjectFactory();
            xworkContext.getContainer().inject(f);
            f.setApplicationContext(_applicationContext);
            f.setAutowireStrategy(_autoWireStrategy);
            return f;
        }
    });
}
Also used : Context(com.opensymphony.xwork2.inject.Context) ApplicationContext(org.springframework.context.ApplicationContext) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Aggregations

Test (org.junit.Test)15 JAXBElement (javax.xml.bind.JAXBElement)14 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)13 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)11 QName (javax.xml.namespace.QName)11 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 Marshaller (javax.xml.bind.Marshaller)10 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)10 StringWriter (java.io.StringWriter)9 BigInteger (java.math.BigInteger)9 ArrayList (java.util.ArrayList)9 JAXBContext (javax.xml.bind.JAXBContext)9 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)8 Holder (javax.xml.ws.Holder)7 ObjectFactory (org.apache.type_test.types3.ObjectFactory)7 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)6 Book (biblemulticonverter.data.Book)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 XStream (com.thoughtworks.xstream.XStream)5