How to apply some validations in a column in Propel schema? - xsd

I am using Propel schema to create database tables. In a table, i need to create a 'name' column which should hold a 'short string', 'all in lower case', and 'with no spaces', for example:
'join', 'appointment'.
How can I define this column in schema.xml with given constraints? Or do I have to create a custom validator to get it done?

You can define a validate behaviour in your schema.xml.
There are several validators to choose from, you would probably use the Choice Validator.
Example:
<table name='TableName'>
...
<column name='name' type='varchar' size='20' />
<behavior name="validate">
<parameter name="rule1" value="{column: name, validator: Choice, options: {message: Please enter a valid name }}" />
</behavior>
</table>

Related

Component attributes do not support complex content (mixed C# and markup) error message

I am working on validation on a form in a blazor server application.
I created the component below that I am using
#* Inherits from the original InputText component *#
#inherits InputText
#* Bind the oninput event *#
<input #attributes="AdditionalAttributes"
class="#CssClass"
value="#CurrentValue"
#oninput="EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString)" />
#code {
}
I am using the inputTextOnInput in this form
<EditForm EditContext="#EditContext">
<DataAnnotationsValidator />
<div class="mb-5">
<label for="projectnameinput" class="form-label">Name your project*</label>
<InputTextOnInput class="form-control form-control-lg cust #pNameValidation" id="projectnameinput" #bind-value="projectModel.ProjectName" #onkeyup=KeyboardEventHandler />
</div>
</EditForm>
since I created this I started getting the error message below
Component attributes do not support complex content (mixed C# and markup). Attribute: 'class', text: 'form-controlform-control-lgcustpNameValidation
Do you have an idea of what this implies?
You cannot use the class attribute in your new component if you have declared a specific parameter for that.
<InputTextOnInput class="form-control form-control-lg cust #pNameValidation" id="projectnameinput" #bind-value="projectModel.ProjectName" #onkeyup=KeyboardEventHandler />
you need to remove class from above and pass it via CssClass.
For some reason Blazor/Razor don't let you mix text literals and variables within an attribute value. So when you try and do
<InputTextOnInput class="form-control form-control-lg cust #pNameValidation" id="projectnameinput" #bind-value="projectModel.ProjectName" #onkeyup=KeyboardEventHandler />
the class statement is invalid because it contains literals "form-control", "form-control-lg" and "cust" and also a variable "#pNameValidation".
My solution to this problem was to create a little method on a component base class which allows mixing the two things.
public string Class(string classStr, params string[] objStrs)
{
var output = new StringBuilder();
output.Append(classStr);
output.Append(' ');
output.AppendJoin(' ', objStrs);
return output.ToString();
}
now all I have to do is to write my line like this
<InputTextOnInput class="#Class("form-control form-control-lg cust", pNameValidation)" id="projectnameinput" #bind-value="projectModel.ProjectName" #onkeyup=KeyboardEventHandler />
and by using params, you can also just add as many string variables as you want.

Add additional fields in registration using Jhipster 4.10.2

I need to add phone number to the registration page and need to save it in the db as well. I followed following link.
http://www.jhipster.tech/tips/022_tip_registering_user_with_additional_information.html
But since here Jhispter version is changed code is bit different than the code in above link. So I am bit confusing to go with it. According to the link instructions I did upto "Updating ManagedUserVM". Then after I need the help since code is differed.
It really didn't change that much, and the logic remains the same.
The registerAccount function should look like this now :
public void registerAccount(#Valid #RequestBody ManagedUserVM managedUserVM) {
if (!checkPasswordLength(managedUserVM.getPassword())) {
throw new InvalidPasswordException();
}
userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase()).ifPresent(u -> {throw new LoginAlreadyUsedException();});
userRepository.findOneByEmailIgnoreCase(managedUserVM.getEmail()).ifPresent(u -> {throw new EmailAlreadyUsedException();});
User user = userService.registerUser(managedUserVM, managedUserVM.getPassword(), managedUserVM.getPhone());
mailService.sendActivationEmail(user);
}
And the registerUser function in the UserService (which is a rename of the former createUser) :
public User registerUser(UserDTO userDTO, String password, String phone) {
// JHipster code omitted for brevity
...
// Create and save the UserExtra entity
UserExtra newUserExtra = new UserExtra();
newUserExtra.setUser(newUser);
newUserExtra.setPhone(phone);
userExtraRepository.save(newUserExtra);
log.debug("Created Information for UserExtra: {}", newUserExtra);
return newUser;
}
Just note that you may have to manually change your database changelog (if using a SQL database) to correctly link the ids of User and UserExtra, so it looks like this :
<createTable tableName="user_extra">
<column name="phone" type="varchar(255)">
<constraints nullable="true" />
</column>
<column name="user_id" type="bigint">
<constraints primaryKey="true" nullable="false" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
</createTable>

How to notify List component that one item has changed the size?

I would like to render a list of items using react-virtualized, however some of the items could change the size.
I have added a demo, where each item has a button and when someone clicks the button then the item needs to expand and push the below items lower:
https://plnkr.co/edit/GG2bSIC5M1Gj7BR1pOii
The use case is similar to facebook posts, when someone comments it will expand the post and push the other posts lower.
ReactDOM.render(
<List
className='List'
autoHeight
width={300}
height={400}
rowCount={list.length}
rowHeight={30}
rowRenderer={
({ index, isScrolling, key, style }) => (
<div
className='Row'
key={key}
style={style}
>
{list[index]}
<Expander /> /* contains the button, which when click it will expand more text*/
</div>
)
}
/>,
document.getElementById('example')
Is any way to achieve this?
UPDATE
I am realizing that there must be a way to force the List to update items and recalculate positions. There is an example with InfiniteLoader (react-virtualized example) which is using registerChild in the List as a ref. And it seems that when InfiniteLoader receives answer from the server it capable of forcing list to re-render rows.
I have tried another example with forceUpdate on list, however the List is still not updating.
https://plnkr.co/edit/RftoShEkQW5MR5Rl28Vu
As per the Documentation forceUpdateGrid() should be called instead of forceUpdate().
https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#public-methods
I faced the similar issue and solved it by calling forceUpdateGrid() inside componentWillReceiveProps method.
componentWillReceiveProps(){
this.refs.forceUpdateGrid();
}
render(){
<List
ref={ref => this.refs = ref}
.....
/>
}
Try using Collection from react-virtualized instead of List. It should help :)
add key={Math.random()} the parent of the list item solved my issue.
<ListWidget key={Math.random()}>
<Autosizer>{
.....
<List
.....
/>
.....
}</Autosizer>
</ListWidget>
Note: not recommended, it's just a workaround to get PR accepted

Lotus Notes and C#: NotesRichTextItem how to recreate content or loop through elements in respective order

I am currently exporting a lotus notes database using the C# Interop Domino assembly from NuGet,
I haven't found a way to identify objects or elements in a NotesRichTextItem in the order they were entered, for example, maybe I enter a paragraph first, then a table , then an attachment.
Is there a way to loop through the elements in their respect order ?
I have found a way to find elements with FindFirstElement, but you have to pass what element type you are looking for, this is very difficult as extracting all elements without order would make the content to lose its context.
thanks
There is a way to analyze Notes document's RichText items using DXL - a special XML format for Notes. Use DxlExporter to export a Notes document to DXL format. You can "walk" then through XML and get the content of RichText item with elements in right order.
For this RichText item e.g.
you'd get this DXL
<item name='Body'>
<richtext>
<pardef id='1'/>
<par def='1'>aaaaaaa</par>
<table widthtype='fixedleft' refwidth='1.0667in'>
<tablecolumn width='0.6729in'/>
<tablecolumn width='0.3938in'/>
<tablerow>
<tablecell>
<pardef id='3' keepwithnext='true' keeptogether='true'/>
<par def='3'>111</par></tablecell>
<tablecell>
<pardef id='4' keepwithnext='true' keeptogether='true'/>
<par def='4'>222</par></tablecell>
</tablerow>
<tablerow>
<tablecell><par def='3'>333</par></tablecell>
<tablecell><par def='4'>444</par></tablecell>
</tablerow>
</table>
<pardef id='5' leftmargin='1.2500in' list='bullet'/>
<par def='5'>xxx</par>
<par def='5'>yyy</par>
<par def='5'>zzz</par>
<pardef id='6' leftmargin='1in'/>
<par def='6'>
<attachmentref name='icon16.gif' displayname='icon16.gif'>
<picture height='34px' width='61px'>
<notesbitmap>lQAmAAAAAAAAAAAAA...</notesbitmap>
<caption>icon16.gif</caption>
</picture>
</attachmentref>
</par>
</richtext>
</item>
Here is a Java agent which exports selected documents to a file.
import lotus.domino.*;
public class JavaAgent extends AgentBase {
#Override
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
DocumentCollection dc = agentContext.getUnprocessedDocuments();
String filename = "c:/temp/exportDocs.dxl";
Stream stream = session.createStream();
if (stream.open(filename)) {
stream.truncate();
DxlExporter exporter = session.createDxlExporter();
exporter.setRichTextOption(0);
exporter.setMIMEOption(0);
stream.writeText(exporter.exportDxl(dc));
} else {
System.out.println("Cannot open " + filename);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Unfortunately the API gives you no way to do this:
Navigation is within elements of the same type. You can find or get
the first element of a type, the next element of a type, and the nth
element of a type. You cannot find or get an element regardless of
type.
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.main.doc/H_NOTESRICHTEXTNAVIGATOR_CLASS.html
UPDATE: I forgot to mention that you may want to check out a third-party tool from Genii Software called MidasLSX that possibly could help you. http://www.geniisoft.com/showcase.nsf/MidasLSX

How do you add a new attribute to a dataset node in OpenLaszlo platform?

How do you add a brand new attribute to a node in an OpenLaszlo XML dataset?
The way to do this is to use the lz.datapointer.setNodeAttribute() function. If you use the setNodeAttribute() function with an attribute name that does not already appear on the node, a new one will be created.
In the sample OpenLaszlo application below, if you press the button titled [displayXML] after you compile the program, you will see the XML dataset before any changes are made does not contain any "fav_saying" attribute.
After you click the [updateAttribute] button to add the favorite saying for Homer via the setNodeAttribute() method, you can then click the [displayXML] button again and you will see that an attribute called 'fav_saying' has been added to the XML dataset.
<canvas height="665" width="1000" layout="axis: x" debug="true">
<dataset name="myData">
<myXML>
<person firstname="Homer" lastname="Simpson" />
<person firstname="Marge" lastname="Simpson" />
<person firstname="Montgomery" lastname="Burns" />
</myXML>
</dataset>
<button text="displayXML">
<handler name="onclick">
Debug.write(canvas.myData.serialize());
</handler>
</button>
<button text="updateAttribute">
<handler name="onclick">
var dp = canvas.myData.getPointer(); // get datapointer to XML data
dp.setXPath('myXML/person[#firstname="Homer"]'); // set xpath to Homer Simpson
dp.setNodeAttribute('fav_saying', 'DOH!');
</handler>
</button>
</canvas>
You will also see that multiple calls to setNodeAttribute() will not add additional 'fav_saying' attributes. If the program used a different value for the saying every time then the value in the 'fav_saying' attribute would change but there would still only be one 'fav_saying' attribute.

Resources