How to make a DXL attribute that is true if the word "shall" exists in another attribute, in IBM Rational DOORS? - scripting

Trying to make a DXL boolean attribute (called "Is Requirement?") true if the word "shall" exists in another attribute (called "Text"), and otherwise false.
In edit-mode on the DOORS module, I click Edit -> Attributes -> "Is Requirement?" -> Edit... -> check DXL attribute -> Browse... -> New, write the code -> Ok, close all windows, Tools -> Refresh DXL Attributes
Object o
for o in current Module do{
if((o."Text") contains "shall")
{
o."Is Requirement?" = "True"
}
else
{
o."Is Requirement?" = "False"
}
}

Several aspects here:
The code for a DXL attribute is the code for one specific object and one specific attribute, the object is available in the variable obj, the attribute is available in attrDXLName. There is no loop over objects neither in DXL attributes nor in DXL layout columns.
contains has the signature int contains(Buffer b, string word, int offset), it operates on a Buffer, not on a string. You probably want to use bool findPlainText(string s, string sub, int &offset, int &length, bool matchCase[, bool reverse])
o."Text" will return an object reference. But you want to check the content of the attribute. To get the content of a string attribute, you have to cast the object reference to string, e.g. by concatenating the reference with a string. You can use obj."Text" "".
Is there really an attribute "Text" in your module? Usually, people use the attribute "Object Text".
This changes your code to
int offset, length
bool matchCase = true
obj.attrDXLName = findPlainText (obj."Object Text" "", "shall", offset, length, matchCase)
Remember that the type of your DXL attribute must be boolean for this to work.
And last but not least: Are you sure that your condition "Text contains shall" is sufficient? What about all the words that contain "shall" (https://www.thefreedictionary.com/words-containing-shall)? There are some threads about this topic somewhere in the internet. Search for "Requirement DXL shall shallow". And: is "shall" enough? What about "may", "should", "must"?

Related

Sorbet signature for nested hash

I have a method that parses YAML files. The returned object is a nested Hash, where the keys are always Strings and the leaf-values are always strings, e.g.
{
"a" => "foo",
"b" => {
"c" => "bar",
"d" => "baz"
}
}
I don't know in advance how deep the hash is.
The closest I got to typing the return value was the following signature:
T.any(T::Hash[String,String], T::Hash[String,T::Hash[String, T.untyped]])
This is obviously a bad solution, since it doesn't check anything beneath the second nesting, but the documentation about custom types seems a bit sparse.
Is there any way to type nested hashes, using a custom type, nested types or something similar?
Unfortunately, you won't be able to do much more than what you got to at this point. Even though Shapes are supported, they are an experimental feature.
If you really want to go with hashes, you could express it as:
MyType = T.type_alias {T::Hash[String, T.any(String, T::Hash[String, T.untyped])]}
Alternatively, you could use a T::Struct:
class MyType < T::Struct
const :key, String
const :value, T.any(String, MyType)
end
You'd still have the uncertainty of what the type of the value is, but with flow sensitivity, it should be easy to process the structure:
class Processor
extend T::Sig
sig {params(my_object: MyType).returns(String)}
def process(my_object)
key = my_object.key
obj_value = my_object.value # this is needed for flow sensitivity below
value = case obj_value
when String
value
when MyType
process(obj_value)
else
T.absurd(obj_value) # this makes sure that if you add a new type to `value`, Sorbet will make you handle it
end
return "key: #{key}, value: #{value}"
end
end

How do I use JSONSchema to accept any object string value, regardless of its key?

I have a system that is receiving JSON messages which contain metadata from a static analysis of a file. The names of these fields are dynamically generated from the scan and can be any valid string, but the value is always a valid string.
e.g.
{
"filename": "hello.txt",
...
"meta": {
"some file property": "any string",
"some other file property": "another string",
...
}
}
I have no way of knowing what the keys in meta will be before receiving the message, nor do I know how many keys there will be. Is there a way of capturing in a JSONSchema that it doesn't matter what keys are present, so long as their values are always strings?
I think you're looking for additionalProperties
Validation with "additionalProperties" applies only to the child
values of instance names that do not match any names in "properties",
and do not match any regular expression in "patternProperties".
The value of additionalProperties can be a JSON Schema, like so
...
"additionalProperties" : {
"type": "string"
}
...
Feel free to let me know if I've missed anything in my explanation, or ask any further questions.

SharePoint 2010: Error Mapping to Picture Hyperlink with SPMetal

Whenever I have a column of type hyperlink with the format set for pictures, I get an error whenever there is actually a value in that column.
The exception it throws is "Specified cast is not valid".
My thought is that the problem is either here (the FieldType being set to Url):
[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "FOO", Storage = "FOO_", FieldType = "Url")]
public string FOO
{
get
{
return this._FOO;
}
set
{
if ((value != this._FOO))
{
this.OnPropertyChanging("FOO", this._FOO);
this._FOO = value;
this.OnPropertyChanged("FOO");
}
}
}
Or here (it being cast to a string):
private string _FOO;
But I'd have no idea what the proper values for either of those fields should be.
Any help would be greatly appreciated.
It works whenever this field does not have data in it and I JUST used SPMetal to generate the class, so I'll get the two most obvious questions out of the way.
Link to the answer:
https://mgreasly.wordpress.com/2012/06/25/spmetal-and-workflow-associations/
Turns out it is a known bug when mapping lists that have associated workflows.
SPMetal assigns it as a nullable integer when it's supposed to be an Object, hence the cast error.
Workaround: manually edit the mappings to make the type it returns an object or ignore the column by using a parameter map.

How to import data from sql into Word custom properties with vba

I'm evaluating ways of importing field data from a sql database into Word. Each field has small amounts of text in them for company name, legal status, address line, etc. I can pull it into a table, but I don't want the user to see it. I would really like to import the data into a set of custom properties in a template, and then use those to reference in the Word doc using codes. Does anyone have any links or examples that could help me do that?
I have no problem in doing the custom properties side of things. I am not sure how I can get the data into a custom property.
You help would be appreciated.
I haven't found a satisfactory solution to this, and I need to keep it all in VBA, given a few specific restrictions by the client.
I now know that the source is a MSSQL2008 server. I want to source company address and level details in the table, but ideally I want to pot these details into a set of custom properties in the document. I can then reference these into the document, and update the custom properties when needed.
You can do it using an add-in written in for instance C#. With VSTO, you can easily and reliably download facts from most databases and put them in custom properties. An alternative is the use of Invantive Composition, which allows you to do this by specifying it in a model of the template, see this model definition: . Please note that I work at the company that made it, so I'm biased.
If you want to go down the road with C#, use code similar to in for instance ApplicationUtility.cs of your project (code taken from Invantive Control, but put in public here for your convenience):
Getting property value
private object GetWordBuiltInProperty(_Word.Document wordDocument, _Word.WdBuiltInProperty property)
{
try
{
if (wordDocument != null)
{
return wordDocument.BuiltInDocumentProperties[property].Value;
}
}
Or changing it
private void CreateDocumentProperty(_Word.Document wordDocument, string name, MsoDocProperties type, object value)
{
Debug.Assert(wordDocument != null, "Word document cannot be null!");
Debug.Assert(!string.IsNullOrEmpty(name), "Name cannot be null!");
object property = this.GetDocumentProperty(wordDocument, name);
if (property == null)
{
Type t = wordDocument.CustomDocumentProperties.GetType();
t.InvokeMember("Add", BindingFlags.InvokeMethod, null, wordDocument.CustomDocumentProperties, new object[] { name, false, type, value });
}
}
private void CreateOrReplaceDocumentProperty(_Word.Document wordDocument, string name, MsoDocProperties type, object value)
{
Debug.Assert(wordDocument != null, "Word document cannot be null!");
Debug.Assert(!string.IsNullOrEmpty(name), "Name cannot be null!");
object property = this.GetDocumentProperty(wordDocument, name);
if (property == null)
{
//
// Add property.
//
this.CreateDocumentProperty(wordDocument, name, type, value);
}
else
{
//
// Set value.
//
this.SetDocumentPropertyValue(wordDocument, name, value);
}
}
private void SetDocumentPropertyValue(_Word.Document wordDocument, string name, object value)
{
object property = this.GetDocumentProperty(wordDocument, name);
if (property != null)
{
Type t = property.GetType();
t.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { value });
}
}

NSPredicateEditorRowTemplate, specifying of Key Path with spaces?

As per a previous question, I have reluctantly given up on using IB/Xcode4 to edit an NSPredicateEditor and done it purely in code.
In the GUI way of editing the fields, key paths can be specified with spaces, like 'field name', and it makes them work as 'fieldName'-style key paths, while still displaying them in the UI with spaces. How do I do this in code? When I specify them with spaces, they don't work. When I specify them in camelCase, they work but display in camelCase. I'm just adding a bunch of NSExpressions like this:
[NSExpression expressionForKeyPath:#"original filename"]
The proper way to get human readable strings in the predicate editor's row views is to use the localization capabilities of NSRuleEditor and NSPredicateEditor.
If you follow the instructions in this blog post, you'll have everything you need to localize the editor.
As an example, let's say your key path is fileName, you support 2 operators (is and contains), and you want the user to enter a string. You'll end up with a strings file that looks like this:
"%[fileName]# %[is]# %#" = "%1$[fileName]# %2$[is]# %3$#";
"%[fileName]# %[contains]# %#" = "%1$[fileName]# %2$[contains]# %3$#";
You can use this file to put in human-readable stuff, and even reorder things:
"%[fileName]# %[is]# %#" = "%1$[original filename]# %2$[is]# %3$#";
"%[fileName]# %[contains]# %#" = "%3$# %2$[is contained in]# %1$[original filename]#";
Once you've localized the strings file, you hand that file back to the predicate editor, and it'll pull out the translated values, do its magic, and everything will show up correctly.
If you don't want to localize everything, just map the key paths consider overriding value(forKey:) in your evaluated object like this:
class Match: NSObject {
var date: Date?
var fileName: String?
override func value(forKey key: String) -> Any? {
// Alternatively use static dictionary for mapping key paths
super.value(forKey: camelCasedKeyPath(forKey: key))
}
private func camelCasedKeyPath(forKey key: String) -> String {
key.components(separatedBy: .whitespaces)
.enumerated()
.map { $0.offset > 0 ? $0.element.capitalized : $0.element.lowercased() }
.joined()
}
}