Relation samples

Basics

Example of uuid:

  • Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

Then should login using the method "login". You can access the "login" method from webservice object "ws" as is shown below:

ws.login(user, password);

Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method

At this point you can use all the Relation methods from "relation" class as is shown below:

ws.relation.getRelationTypes(RelationType.BIDIRECTIONAL);

Methods

getRelationTypes

Description:

MethodReturn valuesDescription

getRelationTypes(String type)

List<RelationType>

Retrieves a list of all relations defined of a type.

Available types values:

  • RelationType.BIDIRECTIONAL
  • RelationType.PARENT_CHILD
  • RelationType.MANY_TO_MANY

More information at Relation types.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationType;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationType type : ws.relation.getRelationTypes(RelationType.BIDIRECTIONAL)) {
                System.out.println(type);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

addRelation

Description:

MethodReturn valuesDescription

addRelation(String nodeAId, String nodeBId, long relTypeId)

void

Sets a relation between two nodes.

The parameters nodeAId and nodeBId should be any valid document, folder, mail or record UUID.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationType;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationType type : ws.getRelationTypes(RelationType.BIDIRECTIONAL)) {
                // looking for a relation named invoice
                if (type.getTitle().equals("invoice")) {
                    // Relation invoice with budget
                    ws.relation.addRelation("46762f90-82c6-4886-8d21-ad3017dd78a7", "8cd1e072-8595-4dd3-b121-41d622c43f08", type.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteRelation

Description:

MethodReturn valuesDescription

deleteRelation(long relationId)

void

Deletes a relation.

Only when the relation will not be used by any node is able to be deleted, otherwise you'll get an error.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Relation;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (Relation relation : ws.getRelations("46762f90-82c6-4886-8d21-ad3017dd78a7")) {
                // looking for a relation named invoice
                if (relation.getRelationTitle().equals("invoice")) {
                    ws.relation.deleteRelation(relation.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getRelations

Description:

MethodReturn valuesDescription

getRelations(String uuid)

List<Relation>

Retrieves a list of all relations of a node..

The parameters uuid should be any valid document, folder, mail or record UUID.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Relation;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (Relation relation : ws.relation.getRelations("46762f90-82c6-4886-8d21-ad3017dd78a7")) {
                System.out.println(relation);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getRelationGroups

Description:

MethodReturn valuesDescription

getRelationGroups(String uuid)

List<RelationGroup>

Retrieves a list of all relation groups of a node.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationGroup rg : ws.relation.getRelationGroups("46762f90-82c6-4886-8d21-ad3017dd78a7")) {
                System.out.println(rg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

addRelationGroup

Description:

MethodReturn valuesDescription

addRelationGroup(String uuid, String groupName, long type)

void

Adds a relation group at a node.

On a relation group only has sense to apply a relation type of RelationType.MANY_TO_MANY.

More information at Relation types.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationType;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationType type : ws.relation.getRelationTypes(RelationType.MANY_TO_MANY)) {
                if (type.getTitle().equals("staple")) {
                    ws.addRelationGroup("46762f90-82c6-4886-8d21-ad3017dd78a7", "staple group", type.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

addNodeToGroup

Description:

MethodReturn valuesDescription

addNodeToGroup(String uuid, long groupId)

void

Adds a node to an existing relation group.

On a relation group only has sense apply the type RelationType.MANY_TO_MANY.

More information at Relation types.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationGroup rg : ws.relation.getRelationGroups("46762f90-82c6-4886-8d21-ad3017dd78a7")) {
                if (rg.getName().equals("staple group")) {
                    ws.relation.addNodeToGroup("8f101a85-88e7-4abe-8175-c5fea3e17d8b", rg.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteRelationGroup

Description:

MethodReturn valuesDescription

deleteRelationGroup(long groupId)

void

Remove relation group from a node

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationGroup rg : ws.relation.getRelationGroups("8f101a85-88e7-4abe-8175-c5fea3e17d8b")) {
                if (rg.getName().equals("staple group")) {
                    ws.relation.deleteRelationGroup(rg.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

findRelationGroup

Description:

MethodReturn valuesDescription

findRelationGroup(long groupId)

RelationGroup

Finds a relation group by id.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long groupId = 1;
            System.out.println(ws.relation.findRelationGroup(groupId));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setRelationGroupName

Description:

MethodReturn valuesDescription

setRelationGroupName(long groupId, String groupName)

void

Changes the relation group name.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long groupId = 1;
            ws.relation.setRelationGroupName(groupId, "new name");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getAllRelationGroups

Description:

MethodReturn valuesDescription

getAllRelationGroups()

List<RelationGroup>

Retrieves a list of all relation groups.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationGroup rg : ws.relation.getAllRelationGroups()) {
                System.out.println(rg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteRelationGroupItem

Description:

MethodReturn valuesDescription

deleteRelationGroupItem(String uuid, long groupId)

void

Remove a node from a relation group.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.RelationGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (RelationGroup rg : ws.relation.getRelationGroups("930baee0-8712-41b0-85c0-81d21e55742f")) {
                if (rg.getName().equals("staple")) {
                    ws.relation.deleteRelationGroupItem("930baee0-8712-41b0-85c0-81d21e55742f", rg.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}