IBM DOORS: DXL script that follows link chain - scripting

Im totally new in DXL scripting and try to get deeper into it. Unfortunately DXL is not the best documented kind of language.
First of all let me describe the situation. I have 3 different folders. The first folder includes just a start modul. The other both folders include in each case some more modules.
I want to start with the start modul going through all objects inside of it to look out for incoming links. If there is an incoming link I want to follow this link to the outgoing object which is just a further object in a module in the second folder
and switch to it. From there I want to do the same procedure until objects in folder 3 are reached or rather until check if folder 2 module objects have incoming links from folder 3 module objects.
The reason I want to do this is to check if the link chain is complete or not and how many of them are complete or not. Means if folder 1 module objects have incoming links from folder 2 module objects
and folder 2 module objects have incoming links from folder 3 module objects.
Thats want I ve got so far:
pragma runLim, 0
int iAcc = 0
int iRej = 0
int linkChainComplete = 0
int linkChainNotComplete = 0
string startModulPath = "/X/X.1"
Module m
m = read(startModulPath)
Object o
Link l
filtering off
Filter f = hasLinks(linkFilterIncoming, "*")
for o in m do {
bool isComplete = true
set(m, f, iAcc, iRej)
if(iAcc == 0){
isComplete = false
}
else{
for l in o <- "*" do {
Object src = source l;
set(m, f, iAcc, iRej)
if(iAcc == 0){
isComplete = false
}
}
}
if(isComplete){
linkChainComplete++
}
else{
linkChainNotComplete++
}
}
The first question is, am I on the right path?
And one question or rather problem is for example that I want to proof if there are incoming links by using the hasLinks function (concerning this also see "set(m, f, iAcc, iRej) and if(iAcc == 0)" part.
But this function refers to the module (m) instead objects (o). Is there another way to proof if an object has got incoming links or not?
Hope anyone could help me. Thank you very much indeed.

Related

Trying to get property 'path' of non-object

Hello I am having the above error in production but all works well in development. I am using the code bellow to get the path to the main image for the property but it defaults into the else despite the if not being false plus the else does not find the paths even when dump shows that the object has been returned
//check if there are hotels in the selected destination
if($hotels->isNotEmpty()){
//Loop through the hotels
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where(['p_id'=>$hotel->id])->where(['is_main'=>1])->first();
$altbanner = Photo::where(['p_id'=>$hotel->id])->first();
$banner_path = "";
$altText = "";
if($banner!=null){
$banner_path = $banner->path;
$altText = $banner->alt_text;
}else{
$banner_path = $altbanner->path;
$altText = $altbanner->alt_text;
}
Have you checked your database if each hotel has an image? Based on your question and explanation, there is a part of the for each that returns null for the image hence the if part fails and the else return the error. If that is the case then you may want to check and sort it by uploading the image or modifying your checks to handle cases where no image is found.
I think the way you are using the where clause isn't right
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where('p_id',$hotel->id)->where('is_main',1)->first();
$altbanner = Photo::where('p_id',$hotel->id)->first();
// .....
if($banner){
$banner_path = $banner->path;
// ......

Property Photo Files with PHRETS v2

My php code, below, attemps to download all the photos for a property listing. It successfully queries the RETS server, and creates a file for each photo, but the file does not seem to be a functional image. (MATRIX requires files to be downloaded, instead of URLs.)
The list of photos below suggests that it successfully queries one listing id (47030752) for all photos that exist, (20 photos in this case). In a web browser, the files appear only as a small white square on a black background: e.g. (https://photos.atlantarealestate-homes.com/photos/PHOTO-47030752-9.jpg). The file size (4) also seems to be very low, as compared to that of a real photo.
du -s PHOTO*
4 PHOTO-47030752-10.jpg
4 PHOTO-47030752-11.jpg
4 PHOTO-47030752-12.jpg
4 PHOTO-47030752-13.jpg
4 PHOTO-47030752-14.jpg
4 PHOTO-47030752-15.jpg
4 PHOTO-47030752-16.jpg
4 PHOTO-47030752-17.jpg
4 PHOTO-47030752-18.jpg
4 PHOTO-47030752-19.jpg
4 PHOTO-47030752-1.jpg
4 PHOTO-47030752-20.jpg
4 PHOTO-47030752-2.jpg
4 PHOTO-47030752-3.jpg
4 PHOTO-47030752-4.jpg
4 PHOTO-47030752-5.jpg
4 PHOTO-47030752-6.jpg
4 PHOTO-47030752-7.jpg
4 PHOTO-47030752-8.jpg
4 PHOTO-47030752-9.jpg
script I'm using:
#!/usr/bin/php
<?php
date_default_timezone_set('this/area');
require_once("composer/vendor/autoload.php");
$config = new \PHRETS\Configuration;
$config->setLoginUrl('https://myurl/login.ashx')
->setUsername('myser')
->setPassword('mypass')
->setRetsVersion('1.7.2');
$rets = new \PHRETS\Session($config);
$connect = $rets->Login();
$system = $rets->GetSystemMetadata();
$resources = $system->getResources();
$classes = $resources->first()->getClasses();
$classes = $rets->GetClassesMetadata('Property');
$host="localhost";
$user="db_user";
$password="db_pass";
$dbname="db_name";
$tablename="db_table";
$link=mysqli_connect ($host, $user, $password, $dbname);
$query="select mlsno, matrix_unique_id, photomodificationtimestamp from fmls_homes left join fmls_images on (matrix_unique_id=mls_no and photonum='1') where photomodificationtimestamp <> last_update or last_update is null limit 1";
print ("$query\n");
$result= mysqli_query ($link, $query);
$num_rows = mysqli_num_rows($result);
print "Fetching Images for $num_rows Homes\n";
while ($Row= mysqli_fetch_array ($result)) {
$matrix_unique_id="$Row[matrix_unique_id]";
$objects = $rets->GetObject('Property', 'LargePhoto', $matrix_unique_id);
foreach ($objects as $object) {
// does this represent some kind of error
$object->isError();
$object->getError(); // returns a \PHRETS\Models\RETSError
// get the record ID associated with this object
$object->getContentId();
// get the sequence number of this object relative to the others with the same ContentId
$object->getObjectId();
// get the object's Content-Type value
$object->getContentType();
// get the description of the object
$object->getContentDescription();
// get the sub-description of the object
$object->getContentSubDescription();
// get the object's binary data
$object->getContent();
// get the size of the object's data
$object->getSize();
// does this object represent the primary object in the set
$object->isPreferred();
// when requesting URLs, access the URL given back
$object->getLocation();
// use the given URL and make it look like the RETS server gave the object directly
$object->setContent(file_get_contents($object->getLocation()));
$listing = $object->getContentId();
$number = $object->getObjectId();
$url = $object->getLocation();
//$photo = $object->getContent();
$size = $object->getSize();
$desc = $object->getContentDescription();
if ($number >= '1') {
file_put_contents("/bigdirs/fmls_pics/PHOTO-{$listing}-{$number}.jpg", "$object->getContent();");
print "$listing - $number - $size $desc\n";
} //end if
} //end foreach
} //end while
mysqli_close ($link);
fclose($f);
php?>
Are there any suggested changes to capture photos into the created files? This command creates the photo files:
file_put_contents("/bigdirs/fmls_pics/PHOTO-{$listing}-{$number}.jpg", "$object->getContent();");
There may be some parts of this script that wouldn't work in live production, but are sufficient for testing. This script seems to successfully query for the information needed from the RETS server. The problem is just simply that the actual files created do not seem to be functional photos.
Thanks in Advance! :)
Your code sample is a mix of the official documentation and a usable implementation. The problem is with this line:
$object->setContent(file_get_contents($object->getLocation()));
You should completely take that out. That's actually overriding the image you downloaded with nothing before you get a chance to save the contents to a file. With that removed, it should work as expected.

Why is a DOORS Module sometimes null when trying to edit the Module via DXL?

I'm new to DXL programming language in IBM DOORS. However, I think I have managed to do many interesting things: create Modules, create Objects, create Links, delete Objects etc.
However, I have a very specific problem regarding "null" Modules. I've just written null between "" because the modules exist and they are referenced with a correct name.
When doing this:
Module m1 = edit("1. MY_MODULE", false)
save(m1)
close(m1)
An error like this appears:
enter image description here
You could not understand what does that mean as it is spanish. Basically states this: "Module null parameter in the first position of the argument." That means that the "m1" is null, as the parameter for save() method is null.
The point is that it is an error which appears only sometimes. It seems that the Module is null as it has been previously opened and DOORS does not close properly.
Is there any way, any method...whatever to avoid this error?
I assume that the script cannot find the module when another folder is active.
Try
Module m1 = edit ("/myproject/myfolder/mysubfolder/1. MY_MODULE", false)
There might be many reasons that the module can't be opened in edit mode. For example: User do not have write access OR Module is being used by other user, etc.
However, you can get around the error with the below code snippet:
Module m = edit('My_module', false)
if(!null m) {
//execute program
...
}
else {
//do something
}
I hope this helps.
How does your script work? do you open the same module again and again and sometimes get the error or do you open lots of modules and for some of them it works and for others it doesn't? In the latter case, perhaps you misspelled the path. You could add some sanity checks like
string fullPathToMod = "/myproject/myfolder.."
Item i = item fullPathToMod;
if null i then error "there is no item called " fullPathToMod
if "Module" != type i then error "there is an item, but it's not a module, it's a " type i
This is how the Code is structured:
void checkModule(string folderPath, string mName, Skip list, int listSize, int listLastIndex, string headers[], string heading[], string headerKey, bool uniqueKey, string combinedKey[]){
if (module mName){
Folder f = folder(folderPath)
current = f
Module m = edit(folderPath""mName, false)
current = m
Object o = first(m) // error sometimes: Se ha pasado un parametro Module null en una posiciĆ³n de argumento 1
if (o == null){
loadModule(m, list, listSize, listLastIndex, headers, heading)
} else {
updateModule(m, mName, list, listSize, listLastIndex, heading, headerKey, headers, uniqueKey, combinedKey)
save(m)
close(m)
}
if (lastError() != ""){
print "Error: " lastError() "\n"
}
} else {
print "No module " mName ".\n"
}
}
Exactly it breaks in line:
current = m
But as said, only sometimes, not always.
BTW, I'm executing this script via Batch, via Java code. One curious thing is that if I close DOORS, and execute the script it does execute correctly. It is as if it needs to be closed in order to edit modules correctly.
I pressume current can be used more than once with different types of Items. I guess it should not be wrong, but it breaks saying (more or less):
Null value passed to DXL commmand (current Module).
Obviously, it means that m is null, but I cannot see any reason for that.

Lotus/Domino User creation flag fREGExtMailReplicasUsingAdminp: How to specify replication details

I need to program a client to Domino Server using Notes C API which registers a new Lotus Notes user. Using REGNewUser (see http://www-12.lotus.com/ldd/doc/domino_notes/8.5.3/api853ref.nsf/ef2467c10609eaa8852561cc0067a76f/0326bfa2438ebe9985256678006a6ff2?OpenDocument&Highlight=0,REGNew*) and it looks promising except for the fact that I need to make the user's mail file replicate from the specified mail server to the mail server's cluster partner. There is the flag
fREGExtMailReplicasUsingAdminp
and the documentation is very brief about it:
"Create mail replicas via the administration process"
If I google the flag I get 4 (!) hits.
How do I specify where the mail file replica is created? Does anyone have any more information about what this flag is actually doing?
Thanks
Kai
After 3 weeks of research in the Notes C API reference I found:
In REGNewPerson there are 2 structures REG_MAIL_INFO_EXT and REG_PERSON_INFO and if you set the above mentioned flag in REG_PERSON_INFO then you have to provide a list of replica servers in REG_MAIL_INFO_EXT like this:
REG_MAIL_INFO_EXT mail_info, *pmail_info;
REG_PERSON_INFO person_info, *pperson_info;
...
pmail_info = &mail_info;
pperson_info = &person_info;
...
// pmail_info->pMailForwardAddress = NULL; // brauchen wir nicht.
pmail_info->pMailServerName = mailserver;
pmail_info->pMailTemplateName = mailfiletemplate;
// do the list crap for replica servers
if (error = ListAllocate (0, 0, FALSE, &hReplicaServers, &pList, &list_size)) {
goto __error;
}
OSUnlock (hReplicaServers);
pList = NULL;
if (error = ListAddEntry (hReplicaServers, // handle to list
FALSE, // do not include data type
&list_size, // pass list size in memory
0, // index to add
replicationserver, // value to add
(WORD) strlen(replicationserver))) // size of value to add
{
goto __error;
}
// now we can add the handle to the structure
pmail_info->hReplicaServers = hReplicaServers;
...
pperson_info->MailInfo = pmail_info;
...
pperson_info->Flags = fREGCreateIDFileNow | fREGCreateAddrBookEntry | fREGCreateMailFileUsingAdminp;
pperson_info->FlagsExt = fREGExtEnforceUniqueShortName | fREGExtMailReplicasUsingAdminp;
In my case this did the trick.

How can I set a global variable from a script/command line?

I'm trying to create a little menu to switch from "YouCompleteMe" to "Supertab" and vice versa.
function! TabFunction()
if !exists("g:WhatTab")
let g:WhatTab = "Tab function?"
endif
if !exists("g:MenuTab_choices")
let g:MenuTab_choices = "&SuperTab\n&YouCompleteMe"
endif
let n = confirm(g:WhatTab, g:MenuTab_choices, "Question")
if n == 1
let g:SuperTabMappingForward = '<Tab>'
let g:SuperTabMappingBackward = '<S-Tab>'
let g:ycm_key_list_select_completion = ['<C-Tab>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-S-Tab>', '<Up>']
elseif n == 2
let g:SuperTabMappingForward = '<C-Tab>'
let g:SuperTabMappingBackward = '<C-S-Tab>'
let g:ycm_key_list_select_completion = ['<Tab>', '<Down>']
let g:ycm_key_list_previous_completion = ['<S-Tab>', '<Up>']
endif
endfun
This doesn't work.
When I try to check the value of these variables from the commandline
:echo 'global variable'
the values are correct but they don't work as expected.
Is it not possible to declare a global variable like this?
The use of the g: variable prefix ensures that the global variables are set from within a function; this is correct. Your problem is that the plugin configuration variables like g:SuperTabMappingForward are only evaluated once during plugin load (when Vim starts up), but not during runtime. This mechanism wasn't meant for dynamic reconfiguration.
Solutions
Instead of toggling the (ignored) config variables, you have to do the remapping yourself. At least SuperTab defines corresponding <Plug>... targets; I guess YCM does this, too:
if n == 1
imap <Tab> <Plug>SuperTabForward
...
elseif n == 2
imap <C-Tab> <Plug>SuperTabForward
Alternatively, the brute-force variant would be to reload the plugins (:runtime plugin/supertab.vim) to get the changed global variable values to be considered, but that's very inefficient, may cause errors, and makes you work around plugin load guards in addition.