OData Manager

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.3
  • Enterprise
  • Community
  • Planned

Overview

Sense/Net ECMS provides an OData REST API for client side developers and portal builders that opens many aspects of Sense/Net ECMS - e.g. content data and operations. The OData functionality can be accessed by regular POST or GET requests, but we wanted to provide an easier way to access our REST API.

Sense/Net OData Manager manages OData requests towards the Sense/Net Content Repository. It provides shortcuts and helper methods for the most common scenarios.

To use OData manager you will have to add a script reference to the following Javascript file to your content view:

  • /Root/Global/scripts/ODataManager.js

Utility functions

dataRoot

The data root of the Sense/Net OData service.

var dataRoot = odata.dataRoot;

parseODataDate

Parses an OData date/time string into JavaScript Date object.

odata.parseODataDate(yourDate);

createODataDate

Converts a JavaScript Date object into an OData date string.

var date = odata.createODataDate(new Date());

getItemUrl

Gets the URL that refers to a single item in the Sense/Net Content Repository without data root (OData.svc)

var trashPath = odata.getItemUrl('/Root/Trash');

getContentUrl

Gets the URL that refers to a single item in the Sense/Net Content Repository with data root (OData.svc)

var trashPath = odata.getContentUrl('/Root/Trash');

getCollectionUrl

Gets the URL that refers to collection of items in the Sense/Net Content Repository with data root (OData.svc)

var trashPath = odata.getCollectionUrl('/Root/Trash');

getContentUrlbyId

Gets the URL that refers to a single item in the Sense/Net Content Repository by its Id with data root (OData.svc)

var trashPath = odata.getContentUrlbyId(66);

getParentPath

Gets the parent path of the given path.

var parentPath = odata.getParentPath(item.Path);

isItemPath

Tells if a path is an item path.

var isItemPath = odata. isItemPath('/Root/Trash');

isCollectionPath

Tells if a path is a collection path.

var isCollectionPath = odata.isCollectionPath('/Root/Trash');

createCustomAction

Creates a wrapper function for a callable custom OData action.

  • parameters:
    • action (string; required): Name of the action
    • params (array; optional): Array with the params
    • mandatoryParams (array; optional): Array with the mandatory params
    • beforeRequest (function; required): can short-circuit execution if it returns something
    • defaultPath (string; optional): default path
    • isODataFunction (bool; optional): tells if this is an OData function or not (OData function would be called with POST non-OData functions with GET)
var logDocumentActivity = odata.createCustomAction({
    action: "LogDocumentActivity",
    mandatoryParams: ["activity"],
    params: ["time"]
});

Basic odata features

fetchContent

Gets content from the Sense/Net Content Repository via OData using the specified options.

  • parameters:
    • path (string; required): content path
    • async (bool; optional): set true to send requests asyncronously or false to send the syncronously (default value is true)
    • skipGlobalHandlers (bool; optional): set true to skin global eventhandlers
    • $select (string; optional): list of the fields that you want to select
    • $filter (string; optional): filter string
    • $expand (string; optional): list of the fields that you want to expand
    • $top (number; optional): number of the items that you want to get
    • $skip (number; optional): number of the items that you want to skip
    • query (string; optional): custom query string
    • $orderby (string; optional): ordering will be based on the given fieldname and arranging (asc, desc)
    • $inlinecount (allpages | none; optional): set to allpages to get the whole set of items (filter, top, skip are ignored), or none to get the result based on the actual options.
    • metadata (full | minimal | no; optional): this option controls the metadata content in output entities.
var shapesRequest = odata.fetchContent({
     path: odata.getItemUrl(contentItem.Path),
     $select: ["Shapes"],
      metadata: "no"
}).done(function (data) {
      if (!data || !data.d)
          $.error('OData reply is incorrect for shapes request.');
      shapes = data.d.Shapes || null;
});

customAction

Calls a custom action on the given content item in the Sense/Net Content Repository.

  • parameters: You can list custom parameters, that you want to use in your action.
odata.customAction({
      action: "SetDashboardSettings",
      path: odata.getItemUrl(item.Path),
      params: {
            widgetSettings: "[" + JSON.stringify(that.options) + "]"
              },
      success: function (result) {
            //do something
      }
});

saveContent

Save the given content item to the Sense/Net Content Repository.

odata.saveContent({
      contentItem: contentItem,
      metadata: "no",
      $select: ["Id"]
}).done(function (data) {
      //do something
});

createContent

Creates a content item in the Content Repository (without binary properties).

odata.createContent({
      contentItem: {
          DisplayName: displayName,
          __ContentType: "Group"
      },
      path: workspacePath + '/Groups'
}).done(function () {
      //do something
});

Custom odata actions that are built into the Sense/Net core product

moveTo

Moves a content item in the Content Repository to the specified target path.

odata.moveTo({
      params: {
            targetPath: targetPath
         },
         path: odata.getItemUrl(dataItem.Path)
}).done(function () {
         //do something
});

getPermissions

Gets the permission entries of a content item from the Sense/Net Content Repository via OData using the specified options.

odata.getPermissions({
	params: {
	     identity: '/Root/Sites/Default_Site/workspaces/Project/budapestprojectworkspace/Groups/Members'}
                path: odata.getItemUrl(itemPath),
        success: function (data) {
             //do something
        }
});

hasPermissions

Checks for permissions of a content item in the Sense/Net Content Repository via OData using the specified options.

odata.hasPermissions({
	params: {
	      permissions: AddNew,Save
        }
        path: odata.getItemUrl('workspaces/Project/budapestprojectworkspace/Document_Library'),
                success: function (data) {
                    //do something
        }
});

deleteContent

Deletes a content item from the Content Repository.

odata.deleteContent({
     params: {
           permanent: true
     },
     path: odata.getItemUrl(dataItem.Path)
}).done(function () {
     //do something
});

Field editor actions

deleteField

To delete field from a list, or from any other content type that is inherited from list.

odata.DeleteField({
   path: '/Root/Sites/Default_Site/features/form/Contact/Phone'
 
});

editField

To edit a field on a list, or in any other content type that is inherited from list. It can have a 'type' parameter where you can set if you want to modify only the given fields value (which are given in the contentItem parameter) or want to overwrite all the field values with the default values except of the given fields. In the first case you have set 'PATCH' as type in the other case it should be set as 'PUT' (default is PATCH). If you choose 'PUT' you have to give all the compulsory fields (Name, DisplayName, etc).

odata.EditField({
    path: '/Root/Sites/Default_Site/features/form/Contact/Phone',
    contentItem: [{DisplayName: 'New Phone Number Title', Name: 'Phone'}],
    type: 'PUT'
      });

addField

To add new field to a list, or to any other content type that is inherited from list.

odata.AddField({
    path: /Root/Sites/Default_Site/features/form/Contact,
    contentItem: {
        __ContentType: 'ReferenceFieldSetting',
        Name: 'MyReferenceField',
        DisplayName: 'Related documents',
        Compulsory: false,
        AllowMultiple: true
    }      
});

Related links