File

src/lib/service/dms/dms.service.ts

Description

Collection of DMS Services

Index

Methods

Constructor

constructor(backend: BackendService, systemService: SystemService, eventService: EventService)
Parameters :
Name Type Optional
backend BackendService no
systemService SystemService no
eventService EventService no

Methods

copy
copy(id: , typeName: , parentId: , parentTypeName: , createContentLink: )

Copy a DMS Object

Parameters :
Name Optional
id no
typeName no
parentId no
parentTypeName no
createContentLink no
Returns : any

Observable

createDmsObject
createDmsObject(targetType: string, file?: File, indexData?: any, parent?: literal type)

Creates a new DmsObject.

Parameters :
Name Type Optional Description
targetType string no

Target object type name

file File yes

File to be added as DmsObjects content

indexData any yes

Indexdata as plain object where keys are the objects properties and values the values to be applied to it

parent literal type yes

Parent context folder of the new DmsObject

Returns : Observable<literal type>
createLocalCopyOfDMSObject
createLocalCopyOfDMSObject(dmsObject: DmsObject)
Parameters :
Name Type Optional
dmsObject DmsObject no
Returns : DmsObject
createResubmission
createResubmission(dmsObject: DmsObject, subject: string, due: , receiver: , sendEmail: boolean, onlyEmail: boolean)

Create a Resubmission

Parameters :
Name Type Optional
dmsObject DmsObject no
subject string no
due no
receiver no
sendEmail boolean no
onlyEmail boolean no
Returns : any

Observable

createSubscription
createSubscription(dmsObject: DmsObject, subject: string, receiver: , sendemail: boolean, onlyemail: boolean, mode?: SubscriptionMode)

Create a Subscription

Parameters :
Name Type Optional Description
dmsObject DmsObject no
subject string no
receiver no
sendemail boolean no
onlyemail boolean no
mode SubscriptionMode yes

SubscriptionMode

Returns : any

Observable

definalize
definalize(item: DmsObject)

Remove the Finilized Flag from a DMS Object

Parameters :
Name Type Optional
item DmsObject no
Returns : any

Observable

deleteDmsObject
deleteDmsObject(id: string, type?: string, hardDelete?: boolean, force: )

Deletes a DMS object.

Parameters :
Name Type Optional Default value Description
id string no

The id of the dms object to be deleted.

type string yes

Type of object

hardDelete boolean yes

If object should really be deleted or only put into the recycle bin

force no false

If object should be forced to be deleted, even if it is used inside of a process. Default: false

Returns : Observable<any>
finalize
finalize(item: DmsObject)

Set a DMS Object to Finilited

Parameters :
Name Type Optional
item DmsObject no
Returns : any

Observable

getAttachmentByIndex
getAttachmentByIndex(id: string, index: number, type: string, version?: number)

Fetches the specific attachment of a DmsObject.

Parameters :
Name Type Optional
id string no
index number no
type string no
version number yes
Returns : string

string

getAttachments
getAttachments(dmsObject: DmsObject)

Fetches the attachments of a DmsObject.

Parameters :
Name Type Optional
dmsObject DmsObject no

Observable<DmsObjectAttachment[]>

getChildren
getChildren(dmsObject: DmsObject)

Fetches the children of a DmsObject.

Parameters :
Name Type Optional
dmsObject DmsObject no

Observable<DmsObject[]>

getContextPath
getContextPath(id: string)

Returns the context path of the given dms object

Parameters :
Name Type Optional Description
id string no

The id of the object.

Returns : any

The context path of the dms object

getDmsObject
getDmsObject(id: string, type?: string, version?: number, intent?: string, recyclebin?: boolean, withStorageInfo?: boolean, processcount?: boolean)

Fetches a dms object.

Parameters :
Name Type Optional Description
id string no

Objects id

type string yes

Objects type name, will improve load time if provided

version number yes

Target version

intent string yes

Used for server side logging. If you provide an intent, the backend will recognize the request and add it to its logs

recyclebin boolean yes

If true, objects from recyclebin are included

withStorageInfo boolean yes

If true, storageinfo is included on the dms object

processcount boolean yes

If true , number of active process is included

Observable

getDmsObjectByParams
getDmsObjectByParams(params: DmsParams)

Getter for the DMS Objects by params

Parameters :
Name Type Optional
params DmsParams no

Observable

getHistory
getHistory(id: string, type?: string, recyclebin?: boolean)

Fetch the history (audit) of one dms object

Parameters :
Name Type Optional Description
id string no

ID of the dms object to fetch history for

type string yes

Type of the dms object to fetch history for

recyclebin boolean yes

If true, objects from recyclebin are included

Observable<DmsObjectHistoryEntry[]> The history of the dms object

getPreview
getPreview(id: string, type?: string, version?: number, rendition?: string, recyclebin?: boolean)

Generates the URI for getting a DmsObjects preview (PDF rendition).

Parameters :
Name Type Optional Description
id string no

Objects id

type string yes

Objects type name, will improve load time if provided

version number yes

Target version

rendition string yes

Target rendition (PDF)

recyclebin boolean yes

If true, objects from recyclebin are included

Returns : string

string

getSlide
getSlide(id: string, type?: string, version?: number, size?: number)

Generates the URI for getting a DmsObjects slide (Preview image).

Parameters :
Name Type Optional Description
id string no

Objects id

type string yes

Objects type name, will improve load time if provided

version number yes

Target version

size number yes

The size of the preview image in px

Returns : string

string

getStorageInfo
getStorageInfo(id: string, type?: string, version?: number)

Fetches the storage info of a dms object.

Parameters :
Name Type Optional Description
id string no

Objects id

type string yes

Objects type name, will improve load time if provided

version number yes

Target version

Returns : Observable<>

Observable<[]>

getVersions
getVersions(id: string, type?: string)

Fetches the versions of a DmsObject.

Parameters :
Name Type Optional
id string no
type string yes

Observable

move
move(id: , typeName: , parentId: , parentTypeName: )

Move a DMS Object

Parameters :
Name Optional
id no
typeName no
parentId no
parentTypeName no
Returns : any

Observable

removeContent
removeContent(dmsObject: DmsObject)

Remove Content

Parameters :
Name Type Optional
dmsObject DmsObject no
Returns : any

Observable

removeResubmissionsById
removeResubmissionsById(itemId: , dmsObject?: DmsObject)

Remove a Resubmission by a given Id

Parameters :
Name Type Optional
itemId no
dmsObject DmsObject yes
Returns : any

Observable

removeSubscriptionById
removeSubscriptionById(subscriptionId: , dmsObject?: DmsObject)

Reamove a Subscription by a given Id

Parameters :
Name Type Optional
subscriptionId no
dmsObject DmsObject yes
Returns : any

Observable

resolveObjectTypes
resolveObjectTypes(dmsObject: DmsObject)

Reolver of Object Types by DMS Object

Parameters :
Name Type Optional
dmsObject DmsObject no
Returns : DmsObject

DmsObject

restore
restore(id: string, userId: string, type?: string)

Restores File

Parameters :
Name Type Optional Description
id string no

DMS object id

userId string no

user id

type string yes

The dms object type

Returns : any
restoreVersion
restoreVersion(id: string, version: number, type?: string)

Restores an earlier version of the selected DmsObject by adding the earlier version as the new recent version.

Parameters :
Name Type Optional Description
id string no

DMS object id

version number no

The version to be restored

type string yes

The dms object type

Returns : any
share
share(dmsObject: DmsObject, shareWith: literal type[])

Shares a dms object (and its children) with certain users

Parameters :
Name Type Optional Description
dmsObject DmsObject no

The dms object to be shared

shareWith literal type[] no

Array of organization objects to share the object with. Each entry will have the ID of the target organization object as well as an optional param whether or not to also share the dms objects children.

Returns : Observable<any>

Observable being resolved once the request is done

triggerUpdate
triggerUpdate(dmsObject: DmsObject, request: Observable)

if dmsObject is specified, load latest version and trigger Enaio event DMS_OBJECT_UPDATED

Parameters :
Name Type Optional
dmsObject DmsObject no
request Observable<any> no
Returns : any
updateObject
updateObject(id: string, indexdata: any, type?: string, version?: number, checkreferences?: boolean)

Updates an existing dms object.

Parameters :
Name Type Optional Description
id string no

ID of the object to be updated

indexdata any no

Object holding the objects indexdata (property: value)

type string yes

The object type of the object to be updated

version number yes

The current version of the object to be updated

checkreferences boolean yes

If the reference fields should be validated or not

Observable The updated dms object

updateResubmission
updateResubmission(dmsObject: DmsObject, subject: string, due: , receiver: , sendEmail: boolean, onlyEmail: boolean)

Update a Resubmission

Parameters :
Name Type Optional
dmsObject DmsObject no
subject string no
due no
receiver no
sendEmail boolean no
onlyEmail boolean no
Returns : any

Observable

dms.service

import {tap, mergeMap, catchError, map} from 'rxjs/operators';
import {Injectable} from '@angular/core';
import {Observable, of} from 'rxjs';
import {DmsObject, DmsObjectAttachment} from '../../model/dms-object.model';
import {BackendService} from '../backend/backend.service';
import {SystemService} from '../system/system.service';
import {Utils} from '../../util/utils';
import {DmsObjectHistoryEntry} from '../../model/dms-object-history.model';
import {EnaioEvent} from '../events/events';
import {EventService} from '../events/event.service';
import {DmsParams} from './dmsParams.interface';

export enum SubscriptionMode {
  ONLY_INDEX_DATA_CHANGED = 'META',
  ONLY_DOCUMENT_CONTENT_CHANGED = 'CONTENT',
  DMS_OBJECT_CHANGED = 'BOTH'
}

export const resolveObjectRights = [];

/**
 * Collection of DMS Services
 */
@Injectable({
  providedIn: 'root'
})
export class DmsService {

  constructor(private backend: BackendService,
    private systemService: SystemService,
    private eventService: EventService) {
  }

  /**
   * Fetches a dms object.
   *
   * @param id Objects id
   * @param type Objects type name, will improve load time if provided
   * @param version Target version
   * @param intent Used for server side logging. If you provide an intent, the backend will recognize the request and add it to its logs
   * @param recyclebin If true, objects from recyclebin are included
   * @param processcount If true , number of active process is included
   * @param withStorageInfo If true, storageinfo is included on the dms object
   * @returns Observable<DmsObject>
   */
  getDmsObject(id: string, type?: string, version?: number, intent?: string, recyclebin?: boolean, withStorageInfo?: boolean, processcount?: boolean): Observable<DmsObject> {
    const uri = `/dms/${id}`;

    const q = {
      additionalvisibility: true,
      subscription: 'CURRENT',
      resubmission: 'CURRENT',
      rights: 'CURRENT',
      datameta: 'true',
      contextfolder: 'true',
      type,
      recyclebin,
      version,
      processcount: true,
      storageinfo: withStorageInfo,
      '_intent': intent
    };

    return this.backend
      .getViaTempCache(Utils.buildUri(uri, q))
      .pipe(
        catchError(Utils.catchSkip(err => err.status === 404)),
        map(res => this.resolveObjectTypes(new DmsObject(res)))
      );
  }

  /**
   * Getter for the DMS Objects by params
   *
   * @param DmsParams params
   * @returns Observable<DmsObject>
   */
  getDmsObjectByParams(params: DmsParams): Observable<DmsObject> {
    return this.getDmsObject(params.id, params.type, params.version, params.intent, params.recyclebin, params.withStorageInfo);
  }

  /**
   * Fetches the storage info of a dms object.
   *
   * @param id Objects id
   * @param type Objects type name, will improve load time if provided
   * @param version Target version
   * @returns Observable<[]>
   */
  getStorageInfo(id: string, type?: string, version?: number): Observable<[]> {
    const uri = `/dms/${id}/storageinfo`;

    const q = {
      type,
      version
    };

    return this.backend
      .getViaTempCache(Utils.buildUri(uri, q))
      .pipe(
        catchError(Utils.catchSkip(err => err.status === 404)),
        map(res => res.storageinfo)
      );
  }

  /**
   * Reolver of Object Types by DMS Object
   *
   * @param DmsObject dmsObject
   * @returns DmsObject
   */
  resolveObjectTypes(dmsObject: DmsObject): DmsObject {
    dmsObject.type = this.systemService.getObjectType(dmsObject.typeName);

    if (dmsObject.contextFolder) {
      dmsObject.contextFolder.type = this.systemService.getObjectType(dmsObject.contextFolder.typeName);
    }

    return resolveObjectRights.reduce((value, fn) => fn.call(this, value), dmsObject);
  }

  /**
   * Deletes a DMS object.
   * @param id The id of the dms object to be deleted.
   * @param type Type of object
   * @param hardDelete If object should really be deleted or only put into the recycle bin
   * @param force If object should be forced to be deleted, even if it is used inside of a process. Default: false
   */
  deleteDmsObject(id: string, type?: string, hardDelete?: boolean, force = false): Observable<any> {
    const url = `/dms/${id}`;
    const params = {};
    if (type && type.length > 0) {
      params['type'] = type;
    }
    if (hardDelete) {
      params['harddelete'] = hardDelete;
    }
    if (force) {
      params['forcedelete'] = force;
    }
    return this.backend.del(Utils.buildUri(url, params));
  }

  /**
   * Returns the context path of the given dms object
   * @param id The id of the object.
   * @returns The context path of the dms object
   */
  getContextPath(id: string) {
    return this.backend.get(`/dms/${id}/context`)
      .pipe(
        map(
          contextPath => {
            contextPath.forEach(pathItem => {
              pathItem.dmsobject = new DmsObject(pathItem.dmsobject);
            });
            return contextPath;
          }
        ));
  }

  /**
   * Fetches the children of a DmsObject.
   *
   * @param dmsObject
   * @returns Observable<DmsObject[]>
   */
  getChildren(dmsObject: DmsObject): Observable<DmsObject[]> {
    const uri = `/dms/${dmsObject.id}/children`;
    return this.backend.getViaTempCache(Utils.buildUri(uri, {type: dmsObject.type.name})).pipe(
      map((res: any[]) => {
        return res.map(r => this.resolveObjectTypes(new DmsObject(r)));
      }));
  }

  /**
   * Fetches the versions of a DmsObject.
   *
   * @param id
   * @param type
   * @returns Observable<DmsObject>
   */
  getVersions(id: string, type?: string): Observable<DmsObject> {
    const uri = `/dms/${id}/versions`;
    return this.backend.getViaTempCache(Utils.buildUri(uri, {type})).pipe(
      map((res: any) => {
        return new DmsObject(res);
      }));
  }

  /**
   * Fetches the attachments of a DmsObject.
   *
   * @param dmsObject
   * @returns Observable<DmsObjectAttachment[]>
   */
  getAttachments(dmsObject: DmsObject): Observable<DmsObjectAttachment[]> {
    const type = dmsObject.content?.type;
    const version = dmsObject.content?.linked ? -1 : dmsObject.version;
    const contentID = dmsObject.content?.id;
    const uri = Utils.buildUri(`/dms/${contentID}/attachments`, {type, version});
    return !contentID ? of([]) : this.backend.getViaTempCache(uri).pipe(
      catchError(Utils.catchSkip(err => err.status === 404)),
      map((res: any) => res.attachmentinfo && res.attachmentinfo.attachments ? res.attachmentinfo.attachments
        .map((a, i) => new DmsObjectAttachment(Object.assign(a, {id: i, previewUri: this.getAttachmentByIndex(contentID, i, type, version)}))) : []
      ));
  }

  /**
   * Fetches the specific attachment of a DmsObject.
   *
   * @param id
   * @param index
   * @param type
   * @param version
   * @returns string
   */
  getAttachmentByIndex(id: string, index: number, type: string, version?: number): string {
    const uri = Utils.buildUri(`/dms/${id}/attachments/${index}`, {type, version});
    return this.backend.getServiceBase() + uri;
  }

  /**
   * Generates the URI for getting a DmsObjects slide (Preview image).
   *
   * @param id Objects id
   * @param type Objects type name, will improve load time if provided
   * @param version Target version
   * @param size The size of the preview image in px
   * @returns string
   */
  getSlide(id: string, type?: string, version?: number, size?: number): string {
    return Utils.buildUri(
      this.backend.getServiceBase() + '/dms/' + id + '/slide',
      {
        type,
        version,
        height: size
      }
    );
  }

  /**
   * Generates the URI for getting a DmsObjects preview (PDF rendition).
   *
   * @param id Objects id
   * @param type Objects type name, will improve load time if provided
   * @param version Target version
   * @param rendition Target rendition (PDF)
   * @param recyclebin If true, objects from recyclebin are included
   * @returns string
   */
  getPreview(id: string, type?: string, version?: number, rendition?: string, recyclebin?: boolean): string {
    return Utils.buildUri(
      this.backend.getServiceBase() + '/dms/' + id + '/content',
      {
        rendition,
        type,
        version,
        recyclebin
      }
    );
  }

  /**
   * Updates an existing dms object.
   *
   * @param id ID of the object to be updated
   * @param indexdata Object holding the objects indexdata (property: value)
   * @param type The object type of the object to be updated
   * @param version The current version of the object to be updated
   * @param checkreferences If the reference fields should be validated or not
   * @returns Observable<DmsObject> The updated dms object
   */
  updateObject(id: string, indexdata: any, type?: string, version?: number, checkreferences?: boolean): Observable<DmsObject> {
    const url = Utils.buildUri(`/dms/${id}`, {type, version, checkreferences});
    return this.triggerUpdate(<any>{id, type, typeName: type}, this.backend.put(url, indexdata));
  }

  /**
   * Fetch the history (audit) of one dms object
   *
   * @param id ID of the dms object to fetch history for
   * @param type Type of the dms object to fetch history for
   * @param recyclebin If true, objects from recyclebin are included
   * @returns Observable<DmsObjectHistoryEntry[]> The history of the dms object
   */
  getHistory(id: string, type?: string, recyclebin?: boolean): Observable<DmsObjectHistoryEntry[]> {
    const uri = `/dms/${id}/audit`;
    return this.backend.getJson(Utils.buildUri(uri, {type: type, recyclebin: recyclebin})).pipe(map((res) => res.audit.map((auditEntry) => new DmsObjectHistoryEntry(auditEntry))));
  }

  /**
   * Restores an earlier version of the selected DmsObject by adding the earlier version
   * as the new recent version.
   *
   * @param id DMS object id
   * @param version The version to be restored
   * @param type The dms object type
   * @return
   */
  restoreVersion(id: string, version: number, type?: string) {
    const uri = `/dms/restoreversion/${id}/${version}`;
    return this.backend.post(Utils.buildUri(uri, {type: type}), null);
  }

  /**
 * Restores File
 * @param id DMS object id
 * @param type The dms object type
 * @param userId user id
 * @return
 */
  restore(id: string, userId: string, type?: string) {
    const uri = `/dms/restore/${id}?userid=${userId}`;
    return this.backend.put(uri);
  }

  /**
   * if dmsObject is specified, load latest version and trigger Enaio event DMS_OBJECT_UPDATED
   *
   * @param dmsObject
   * @param request
   * @return
   */
  triggerUpdate(dmsObject: DmsObject, request: Observable<any>) {
    return !dmsObject ? request : request.pipe(
      mergeMap(() => this.getDmsObject(dmsObject.id, dmsObject.typeName)),
      tap(_dmsObject => this.eventService.trigger(EnaioEvent.DMS_OBJECT_UPDATED, _dmsObject)));
  }

  /**
   * Remove Content
   *
   * @param DmsObject dmsObject
   * @returns Observable<any>
   */
  removeContent(dmsObject: DmsObject) {
    const uri = `/dms/${dmsObject.id}/content`;
    return this.triggerUpdate(dmsObject, this.backend.del(uri));
  }

  /**
   * Creates a new DmsObject.
   * @param targetType Target object type name
   * @param file File to be added as DmsObjects content
   * @param indexData Indexdata as plain object where keys are the objects properties and values the values to be applied to it
   * @param parent Parent context folder of the new DmsObject
   */
  createDmsObject(targetType: string, file?: File, indexData?: any, parent?: {id: string, type?: string}): Observable<{id: string, uri: string}> {

    const formData = new FormData();
    if (indexData) {
      formData.append('data', new Blob([JSON.stringify(indexData)], {
        type: 'application/json'
      }));
    } else {
      formData.append('noindexdata', '');
    }

    if (file) {
      formData.append('files[]', file, Utils.encodeFileName(file.name));
    }

    let uri = `/dms/create/${targetType}`;
    if (parent) {
      uri = Utils.buildUri(uri, {
        parentId: parent.id,
        parentType: parent.type
      });
    }
    return this.backend.postMultiPart(uri, formData, null, {headers: {}});
  }

  /**
   * Create a Subscription
   *
   * @param DmsObject dmsObject
   * @param string subject
   * @param receiver
   * @param boolean sendemail
   * @param boolean onlyemail
   * @param mode SubscriptionMode
   * @returns Observable<any>
   */
  createSubscription(dmsObject: DmsObject, subject: string, receiver, sendemail: boolean, onlyemail: boolean, mode?: SubscriptionMode) {
    const uri = `/dms/subscription/${dmsObject.id}`;
    return this.triggerUpdate(dmsObject, this.backend.post(Utils.buildUri(uri, {
      subject,
      type: dmsObject.typeName,
      receiver,
      sendemail,
      onlyemail,
      mode
    }), {})
    );

  }

  /**
   * Create a Resubmission
   *
   * @param DmsObject dmsObject
   * @param string subject
   * @param due
   * @param receiver
   * @param boolean sendEmail
   * @param boolean onlyEmail
   * @returns Observable<any>
   */
  createResubmission(dmsObject: DmsObject, subject: string, due, receiver, sendEmail: boolean, onlyEmail: boolean) {
    const uri = `/dms/resubmission/${dmsObject.id}`;
    return this.triggerUpdate(dmsObject, this.backend.post(Utils.buildUri(uri, {
      subject,
      type: dmsObject.typeName,
      receiver,
      due: due ? due.toISOString() : '',
      sendemail: sendEmail,
      onlyemail: onlyEmail
    }), {})
    );
  }

  /**
   * Reamove a Subscription by a given Id
   *
   * @param subscriptionId
   * @param DmsObject dmsObject
   * @returns Observable<any>
   */
  removeSubscriptionById(subscriptionId, dmsObject?: DmsObject) {
    return this.triggerUpdate(dmsObject, this.backend.del(`/messageprovider/subscription/${subscriptionId}`));
  }

  /**
   * Remove a Resubmission by a given Id
   *
   * @param itemId
   * @param DmsObject dmsObject
   * @returns Observable<any>
   */
  removeResubmissionsById(itemId, dmsObject?: DmsObject) {
    return this.triggerUpdate(dmsObject, this.backend.del(`/dms/resubmission/${itemId}`));
  }

  /**
   * Update a Resubmission
   *
   * @param DmsObject dmsObject
   * @param string subject
   * @param due
   * @param receiver
   * @param boolean sendEmail
   * @param boolean onlyEmail
   * @returns Observable<any>
   */
  updateResubmission(dmsObject: DmsObject, subject: string, due, receiver, sendEmail: boolean, onlyEmail: boolean) {
    return this.removeResubmissionsById(dmsObject.id).pipe(mergeMap(() => {
      return this.createResubmission(dmsObject, subject, due, receiver, sendEmail, onlyEmail);
    }));
  }

  /**
   * Shares a dms object (and its children) with certain users
   * @param dmsObject The dms object to be shared
   * @param shareWith Array of organization objects to share the object with. Each entry
   * will have the ID of the target organization object as well as an optional param
   * whether or not to also share the dms objects children.
   * @returns Observable being resolved once the request is done
   */
  share(dmsObject: DmsObject, shareWith: {id: string, shareChildren?: boolean}[]): Observable<any> {
    return this.triggerUpdate(
      dmsObject,
      this.backend.put(
        `/dms/${dmsObject.id}/share`,
        {
          shares: shareWith.map(i => ({
            organizationobject: i.id,
            sharechildren: !!i.shareChildren
          }))
        }
      ));
  }

  /**
   * Move a DMS Object
   *
   * @param id
   * @param typeName
   * @param parentId
   * @param parentTypeName
   * @returns Observable<any>
   */
  move(id, typeName, parentId, parentTypeName) {
    const uri = `/dms/location/${id}`;
    return this.backend.post(Utils.buildUri(uri, {
      type: typeName,
      parentId,
      parentType: parentTypeName
    }), {});
  }

  /**
   * Copy a DMS Object
   *
   * @param id
   * @param typeName
   * @param parentId
   * @param parentTypeName
   * @param createContentLink
   * @returns Observable<any>
   */
  copy(id, typeName, parentId, parentTypeName, createContentLink) {
    const uri = `/dms/copy/${id}`;
    return this.backend.post(Utils.buildUri(uri, {
      type: typeName,
      parentId,
      parentType: parentTypeName,
      createcontentlink: createContentLink
    }), {});
  }

  /**
   * Set a DMS Object to Finilited
   *
   * @param DmsObject item
   * @returns Observable<any>
   */
  finalize(item: DmsObject) {
    const url = '/dms/finalize/' + item.id + '?type=' + item.typeName;
    return this.triggerUpdate(item, this.backend.put(url));
  }

  /**
   * Remove the Finilized Flag from a DMS Object
   *
   * @param DmsObject item
   * @returns Observable<any>
   */
  definalize(item: DmsObject) {
    const url = '/dms/definalize/' + item.id + '?type=' + item.typeName;
    return this.triggerUpdate(item, this.backend.put(url));
  }

  createLocalCopyOfDMSObject(dmsObject: DmsObject): DmsObject {
    const base = {
      id: dmsObject.id,
      title: dmsObject.title,
      description: dmsObject.description,
      version: dmsObject.version,
      versions: dmsObject.versions,
      data: dmsObject.data,
      type: dmsObject.typeName,

      activeversion: dmsObject.isActiveVersion,
      finalized: dmsObject.isFinalized,
      favorite: dmsObject.isFavorite,
      folder: dmsObject.isFolder,
      iscontextfolder: dmsObject.isContextFolder,
      processcount: dmsObject.processcount,

      contextfolder: dmsObject.contextFolder ? {
        id: dmsObject.contextFolder.id,
        type: dmsObject.contextFolder.typeName,
        title: dmsObject.contextFolder.title,
        description: dmsObject.contextFolder.description
      } : null,

      created: dmsObject.created,
      modified: dmsObject.modified,

      lock: !dmsObject.lock ? 'NOT_LOCKED' : dmsObject.lock.by.me ? 'LOCKED_BY_SESSION_USER' : 'LOCKED_BY_OTHER_USER',
      lockinfo: dmsObject.lock ? {username: dmsObject.lock.by.name, usertitle: dmsObject.lock.by.label, time: dmsObject.lock.on} : null,

      rights: [{
        privileges: {
          select: dmsObject.rights.select,
          edit: dmsObject.rights.edit,
          share: dmsObject.rights.share,
          delete: dmsObject.rights.delete,
          finalize: dmsObject.rights.finalize,
          recycle: dmsObject.rights.recycle
        }
      }],
      shares: dmsObject.shares,
      contentid: dmsObject.content ? dmsObject.content.id : null,
      contenttype: dmsObject.content ? dmsObject.content.type : null,
      contentcount: dmsObject.content ? dmsObject.content.count : null,
      contents: dmsObject.content ? dmsObject.content.contents : null,

      subscriptions: dmsObject.subscriptions,
      resubmissions: dmsObject.resubmissions,
      additionalvisibility: dmsObject.additionalvisibility
    };

    let copiedDmsObject = new DmsObject(base);
    copiedDmsObject.type = dmsObject.type;

    return copiedDmsObject;
  }

}

results matching ""

    No results matching ""