How do I find a files master (or version)?

Started by ubacher, June 30, 2017, 08:43:12 PM

Previous topic - Next topic

ubacher

I can find out if a file is a master or a version. This is returned by v1/get/files. But, given a file is a master, how do I find the corresponding
version?
I thought fileinfo might but it does not.

thrinn

Maybe v1/files/relations? I did not try it, but from the Web Services documentation it might help you.
Thorsten
Win 10 / 64, IMatch 2018, IMA

thrinn

Okay, a quick test:
The following snippet returns all versions for the focused file (provided the focused file is a master, of course):

IMWS.get('v1/files/relations', {
                idlist: IMatch.idlist.fileWindowFocusedFile,
                type: 'versions'
            }).then(response => {
                console.log(response);
            });


Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

I have extended the File Relations sample app to also fetch the versions of the focused file when it is a master.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

Thank you both.
In the meantime I have figured out the response:
response.files[jj].masters.files[ii].name
jj files searched, ii versions/masters files returned

where masters is replaced by versions - depending on the direction of the search.

What makes the code to find all masters( versions) quite a bit more involved is the handling of cascading relationships:
The master which I find may in turn be a version and so on......

Note that the returned response also includes a field versionState, a 3 indicates the found file is both a master and a version




Mario

Quotequite a bit more involved is the handling of cascading relationships:
The master which I find may in turn be a version and so on......

Yeah, welcome to the club. I need to figure out such things all the time. When I say "relations are complex" you now may get have better insight  ;)
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

akirot

Help needed please - can't see the wood for the trees.
How do I list (with the in September changed relations endpoint) the definitionName of a version of a file?
How would the relations sample app look like (not only listing the version files ids but the definitionNames, too)?
A code snippet would be very much appreciated.

Mario

The File Relations Sample app shows the name of the relation definition.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

If you have (only) the id of a file you use the v1/files endpoint to get other information (like the name).

akirot

Thank you both for feedback.
@Mario: Yes, the relations sample app in the lower part of the window lists the configured(!) relation definitions, now including the "Verbs" part. That's the easy part :-)

The upper part shows the focused file and Ids of the versions (if the focused file is a master).
What I currently don't manage is: How do I access the e.g. name of the relation definition by which these versions are related to the master.

I know, the (in September) modified files/relations endpoint contains this info (besides the IDs of the versions). Somehow the info is nested and I need help to access this info please. An extended code snippet of the sample app not only listing the version IDs but also the relations they are based on would help.

(Sidenote: Apparently the built in help [via /discover] seems to be not current as far as the files/relations endpoint is concerned, too.)

@ubacher: My challenge is not to find the name of an Id (which you get via the v1/files endpoint) but the relation (and corresponding info) by which a master and version(s) are related.

thrinn

If you only want the definition name, it it returned as version.definitionName.
I just added one line after line 230 of the sample app:

// For each requested file
response.files.forEach(function (f) {
  // For each version definition
  f.versions.forEach(function (version) {
    // List all file ids
    version.files.forEach(function (id) {
      if (versions != '') versions += ',';
      versions += id;
      // ADD THE RELATION DEFINITION NAME
      versions += " " + version.definitionName;
    }, this);
  }, this);
}, this);


Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

#11
Quote(Sidenote: Apparently the built in help [via /discover] seems to be not current as far as the files/relations endpoint is concerned, too.)

I can't follow, sorry. Please just tell me if there is a typo, a missing or extra parameter or whatever you are concerned about...

Displaying the Relation Definition Name

I can only recommend to look at the responses in your debugger or dump them to the console.
This tells you immediately what IMWS returns for a given endpoint.

In case of the /files/relations endpoint, the output looks like this:



This tells you all you need to know. The name of the definition and its id is returned, and an array with the file ids for that definition.
If there is more than one definition applied, the response contains more than one object like this. Easy.

To change the sample app to include the definition name I did a similar thing as thrinn. I changed the code to


// Get the file ids for all versions into a string.
// NOTE: A file may be a master but have no versions!
var versions = '';
var first;
// For each requested file
response.files.forEach(function(f) {
    // For each version definition
    f.versions.forEach(function(version) {
        // List all file ids
        versions += ' (' + version.definitionName + ') ';
        first = true;
        version.files.forEach(function(id) {
            if (!first) versions += ',';
            versions += id;
            first = false;
        }, this);
    }, this);
}, this);

$('#focused-file-versions').text(versions);



And this produces output like:

Versions: (NEF Versions) 1612,1613,1614,1615,1616,1617,1618 (Test Version) 1,2,3

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

akirot

Super - thank you all, that's what I was looking for.
Some things are too simple. I had a knot in my brain. Since the (now) recent version of the sample app listed all versions regardless of the underlying relation I somehow did not know how to access the relation definition which is a level higher in the grouping hierarchy of the output/response.

@Mario: I'll come back to my sidenote (with a screen shot) as soon as I'm back home and have  access to IMatch again.

A good start into the week :-)