0% found this document useful (0 votes)
68 views

Custom Patch

The document describes a patch that was created on June 26, 2017. It contains functions for exporting versions of an object from a content management system. The functions get metadata for each version, including attributes, files, and information about the author. It also checks for available disk space and creates necessary directories before writing the version metadata files.

Uploaded by

utsav1521
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Custom Patch

The document describes a patch that was created on June 26, 2017. It contains functions for exporting versions of an object from a content management system. The functions get metadata for each version, including attributes, files, and information about the author. It also checks for available disk space and creates necessary directories before writing the version metadata files.

Uploaded by

utsav1521
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 15

# Patch PAT26062017000001 created at Mon Jun 26 17:51:41 2017

m {'kernel','oe'}
o {'pat26062017000001::document',&&oe::Objects::document}
N document
f ExportVersions
s

function Assoc ExportVersions( Object prgCtx, DAPINODE node, String location )

Assoc retval = Assoc.CreateAssoc()


Assoc result
List versions
Integer max, i
Assoc metadata, root
Assoc attr = Assoc.CreateAssoc()

Object dapiCtx = prgCtx.DSession()


Object llNode
Integer lengthOfRootFolder =
Length( $OE.Export.fDocumentPath )

retval.ok = TRUE
retval.errMsg = ""

//SEB MT-01 Variables Declaration


List metaList = $OE.MetadataSubsystem.GetItems()
Object metaObj
Dynamic checkVal

// set <node> attributes

attr.action = "addversion"
attr.type = this.OSParent.OSName

// get a list of DAPIVersions

versions = DAPI.ListVersions( node )


if IsNotError( versions )
max = Length( versions )
else
retval.ok = FALSE
retval.errMsg =
Str.Format( [OE_ERRMSG.CouldNotListVersions], node.pID )
return retval
end

// we aready created the first version, so skip it

if max > 1

for i = 2 to max
result = .CreateFile( versions[i] )
if result.ok

metadata = Assoc.CreateAssoc()
// Get the major/minor version info

llNode = $LLIAPI.LLNodeSubsystem.GetItem(
node.pSubType )

if IsNotError( llNode )

if
llNode.IsMajorMinorNode( dapiCtx, node )

metadata.versionmajor =
Str.ValueToString( versions[i].pVerMajor )
metadata.versionminor =
Str.ValueToString( versions[i].pVerMinor )

end

else

retval.ok = FALSE
retval.errMsg =
Str.Format( [OE_ERRMSG.CouldNotGetNode], node.pID )
return retval

end

metadata._attr = attr

metadata.file= result.fileName

metadata.location = location
metadata.mime = versions[i].pMIMEType
metadata.created = $OE.Utils.Date2OIDate(
versions[i].pCreateDate )
metadata.modified =
$OE.Utils.Date2OIDate( versions[i].pModifyDate )
metadata.filename = versions[i].pFILENAME

// SEB MP-01 Get the Version specific


Category Information

//Inorder to get the specific versions


Metatadata Values below attribute defines it
metadata.versionNo=i

if ( retval.ok )

for metaObj in metaList

if ( metaObj.fKey ==
'category')

checkVal =
metaObj.Execute( prgCtx, node, metadata )
if ( !checkVal.ok )

retval.ok = FALSE
retval.errMsg =
checkVal.errMsg
break
end

end

end

//Delete the Version key


Assoc.Delete(metadata,'versionNo')

end

result =
$OE.Utils.GetUserNameFromID( prgCtx, versions[i].pOwner )
if result.ok
metadata.createdby = result.name
end

root = Assoc.CreateAssoc()
root.node = metadata

$OE.Export.WriteMetadata( root )

else
// log error but continue looping
$OE.Export.WriteErrorLog( result.errMsg )
end
end

end

return retval

end

sEND
f GetMetadata
s
/**
* This function will get object specific metadata (if any)
*
* @param {Object} prgCtx
* @param {DAPINODE} node
* @param {Assoc} metadata
*
* @return {Assoc}
* @returnFeature {Boolean} ok
* @returnFeature {String} errMsg
*
*/
function Assoc GetMetadata( \
Object prgCtx, \
DAPINODE node, \
Assoc metadata )

Assoc retval = Assoc.CreateAssoc()


Assoc result
DAPIVERSION version
Integer verNum = $OE.Export.fExportAllVersions ? 1 : 0
String fileName, virtualFileName
Dynamic status
Real fileSize
String dir = ._FormatPath( $OE.Export.fDocumentPath )
String virtualDir =
._FormatPath( $OE.Export.fDocumentPathPrefix, FALSE )
Real freeDiskSpace
String timestamp
List versions

retval.ok = TRUE
retval.errMsg = ""

Object dapiCtx = prgCtx.DSession()


Object llNode

// We need to make sure verNum=1 is really the first version.


(version 1 might have been deleted or promoted)

if ( verNum == 1 )

versions = DAPI.ListVersions( node )

if ( IsNotError( versions ) && Length( versions ) > 0 )

verNum = versions[1].pNumber

//MT-01 SEB Object Exporter to include the filename


tag for first version
metadata.filename = versions[1].pFILENAME

end

end

// get the DAPIVersion

version = DAPI.GetVersion( node, verNum )

if ( IsNotError( version ) )

metadata.mime = version.pMIMEType

// version.pFileDataSize returns bytes, convert to MB


// note: multiply by 1.0 to convert to real

fileSize = (version.pFileDataSize * 1.0) / 1024 / 1024


// Determine whether or not major/minor versions need to be
added to the export

llNode = $LLIAPI.LLNodeSubsystem.GetItem( node.pSubType )

if ( IsNotError( llNode ) )

if ( llNode.IsMajorMinorNode( dapiCtx, node ) )

metadata.versioncontrol = "true"
metadata.versionmajor =
Str.ValueToString( version.pVerMajor )
metadata.versionminor =
Str.ValueToString( version.pVerMinor )

end

else

retval.ok = FALSE
retval.errMsg =
Str.Format( [OE_ERRMSG.CouldNotGetNode], node.pID )
return retval

end

else
retval.ok = FALSE
retval.errMsg = Str.Format( [OE_ERRMSG.CouldNotGetVersion],
verNum, node.pID )
return retval
end

// create the directory

result = $OE.Utils.CreateDirectory( dir )

if ( !result.ok )
retval.ok = FALSE
retval.errMsg = result.errMsg
return retval
end

// check if we have enough free disk space

result = AdminService.GetFreeDiskSpace( dir )

if ( result.ok )

// AdminService.GetFreeDiskSpace returns MB

freeDiskSpace = result.Result

if ( fileSize > freeDiskSpace )


$OE.Export.fCriticalError = TRUE
retval.ok = FALSE
retval.errMsg = [OE_ERRMSG.NotEnoughDiskSpace]
return retval
end

else
retval.ok = FALSE
retval.errMsg = [OE_ERRMSG.CouldNotCalcDiskSpace]
return retval
end

// create a new file

//timestamp = Str.Format( "%1%2", Date.DateToString( Date.Now(),


"%Y%m%d%H%M%S" ), Date.Tick() )

timestamp = $OE.Utils.PadZero( $OE.Export.fDocumentNumber )


$OE.Export.fDocumentNumber += 1

fileName = Str.Format( "%1%2", dir, timestamp )


virtualFileName = Str.Format( "%1%2", virtualDir, timestamp )

if ( File.Exists( fileName ) )

retval.ok = FALSE
retval.errMsg = Str.Format( [OE_ERRMSG.FileAlreadyExists],
fileName )
return retval
else

result = $OE.Utils.CreateFile( fileName )

if ( result.ok )

status = DAPI.FetchVersion( version, fileName )

if ( IsNotError( status ) )

metadata.file = virtualFileName

else
retval.ok = FALSE
retval.errMsg =
Str.Format( [OE_ERRMSG.CouldNotFetchVersion], verNum, node.pID )
return retval
end

else
retval.ok = FALSE
retval.errMsg = result.errMsg
return retval
end

end

// check if we have exceeded the batch limit


if ( Length( File.FileList( dir ) ) >= 5000 )

$OE.Export.fDocumentBatch = Str.Format( "%1%2",


Date.DateToString( Date.Now(), "%Y%m%d%H%M%S" ), Date.Tick() )

end

return retval

end

sEND
o {'pat26062017000001::Metadata',&&oe::Metadata::category}
N Metadata
f Execute
s

function Assoc Execute( Object prgCtx, DAPINODE node, Assoc metadata )

Assoc retval = Assoc.CreateAssoc()


Assoc result
DAPISESSION dSession = prgCtx.DSession().fSession
DAPINODE parentNode
Dynamic attrData
Assoc attrDef, attrVal
Assoc attrValues
List catList = {}
List keys
Dynamic key
List categories = {}
Assoc attr
Assoc cat

retval.ok = TRUE
retval.errMsg = ""

//SEB MT-01 Get the Version No from metadata

if(Assoc.IsKey(metadata,'versionNo'))
result = .GetNodeVersionCategoryData( prgCtx,
node.pID,metadata)
else
result = .GetCategoryData( prgCtx, node.pID )
end

if result.ok

if IsDefined( result.attrdata )

attrData = result.AttrData
attrDef = attrData.fDefinitions
attrVal = attrData.fData

// get a list of the category ID's


keys = Assoc.Keys( attrDef )
for key in keys
catList = List.SetAdd( catList, key[1] )
end

// get the attribute values

result = .GetAttributeValues( attrVal )


if result.ok
attrValues = result.attrValues
else
retval.ok = FALSE
retval.errMsg = result.errMsg
return retval
end

// recurse through the attribute definition to


build up the structure

result = .GetMetadata( prgCtx, attrDef,


attrValues, metadata )
if result.ok
if IsFeature( metadata, "category" )
categories = metadata.category
end
else
retval.ok = FALSE
retval.errMsg = result.errMsg
return retval
end

end // IS DEFINED

else
retval.ok = FALSE
retval.errMsg = result.errMsg
return retval
end

// get categories on the parent object

parentNode = DAPI.GetNodeByID( dSession, DAPI.BY_DATAID,


node.pParentID )
if IsNotError( parentNode )

result = .GetCategoryData( prgCtx, parentNode.pID )


if result.ok

if IsDefined( result.attrdata )

attrData = result.AttrData
attrDef = attrData.fDefinitions

// loop through the parent categories and


see if there are any not in the child
keys = Assoc.Keys( attrDef )
for key in keys

if key[1] in catList
// category is applied on
child, do nothing
else

result =
$OE.Utils.GetNodePath( prgCtx, key[1] )
if result.ok

cat =
Assoc.CreateAssoc()
attr =
Assoc.CreateAssoc()

attr.name = result.path
attr.action = "remove"
cat._attr = attr

categories =
{ @categories, cat }

else
retval.ok = FALSE
retval.errMsg =
result.errMsg
return retval
end

end

end

end

else
retval.ok = FALSE
retval.errMsg = result.errMsg
return retval
end

else
retval.ok = FALSE
retval.errMsg =
Str.Format( [OE_ERRMSG.CouldNotGetNode], node.pID )
return retval
end

if Length( categories )
metadata.category = categories
end

return retval

end
sEND
f fEnabled
v true
f GetCategoryData
s
/**
* This method will retrieve category data for a given node.
*
* @param {Object} prgCtx
* @param {Integer} nodeID
*
* @return {Assoc}
* @returnFeature {Boolean} ok
* @returnFeature {String} errMsg
* @returnFeature {Dynamic} apiError
* @returnFeature {Dynamic} attrData The current category and
attribute data for the given node
*/
function Assoc GetCategoryData( \
Object prgCtx, \
Integer nodeID )

Assoc checkVal
Assoc retVal
Dynamic attrData
Dynamic apiError
String query
String errMsg
RecArray recordset
Integer verNum

Boolean ok = TRUE
Boolean removeInherit = FALSE
Boolean srcRemoveInherit = FALSE
CAPICONNECT cconn = prgCtx.fDbConnect.fConnection
Integer cacheID = 0
Integer srcSourceID = 0
Integer srcSourceVNum = 0
Integer sourceType = $LLIAPI.AttrSourceOriginal

// Get highest attribute version on object

query = "SELECT MIN(VerNum) AS VerNum FROM LLAttrBlobData


WHERE ID = :A1"

recordset = CAPI.Exec( cconn, query, nodeID )

if ( IsNotError( recordset ) )

if ( Length( recordset ) > 0 )

verNum = recordset[ 1 ].VerNum

checkVal =
$LLIApi.AttrUtil.GetAttrDataWithSourceOption( \

prgCtx, \
cacheID, \

nodeID, \

verNum, \

removeInherit, \

sourceType, \

srcSourceID, \

srcSourceVNum, \

srcRemoveInherit )

if ( checkVal.ok == TRUE )

attrData = checkVal.attrData

else

ok = FALSE
errMsg = checkVal.errMsg
apiError = checkVal.apiError
end
end

else

ok = FALSE
errMsg = Str.Format( [OE_ERRMSG.CouldNotQueryTable],
"LLAttrBlobData" )
apiError = recordset
end

retVal.ok = ok
retVal.errMsg = errMsg
retVal.apiError = apiError

retVal.attrData = attrData

return retval
end

sEND
f GetNodeVersionCategoryData
s
/**
* This method will retrieve category data for a given node.
*
* @param {Object} prgCtx
* @param {Integer} nodeID
*
* @return {Assoc}
* @returnFeature {Boolean} ok
* @returnFeature {String} errMsg
* @returnFeature {Dynamic} apiError
* @returnFeature {Dynamic} attrData The current category and
attribute data for the given node
*/
function Assoc GetNodeVersionCategoryData( \
Object prgCtx, \
Integer nodeID,
Assoc metadata )

Assoc checkVal
Assoc retVal
Dynamic attrData
Dynamic apiError
String query
String errMsg
RecArray recordset
Integer verNum

Boolean ok = TRUE
Boolean removeInherit = FALSE
Boolean srcRemoveInherit = FALSE
CAPICONNECT cconn = prgCtx.fDbConnect.fConnection
Integer cacheID = 0
Integer srcSourceID = 0
Integer srcSourceVNum = 0
Integer sourceType = $LLIAPI.AttrSourceOriginal

verNum=metadata.versionNo
query = "SELECT VerNum FROM LLAttrBlobData WHERE ID = :A1 AND
VerNum=:A2"
recordset = CAPI.Exec( cconn, query, nodeID,verNum)

if ( IsNotError( recordset ) )

if ( Length( recordset ) > 0 )

verNum = recordset[ 1 ].VerNum

checkVal =
$LLIApi.AttrUtil.GetAttrDataWithSourceOption( \

prgCtx, \

cacheID, \

nodeID, \

verNum, \

removeInherit, \

sourceType, \

srcSourceID, \

srcSourceVNum, \

srcRemoveInherit )
if ( checkVal.ok == TRUE )

attrData = checkVal.attrData

else

ok = FALSE
errMsg = checkVal.errMsg
apiError = checkVal.apiError
end
end

else

ok = FALSE
errMsg = Str.Format( [OE_ERRMSG.CouldNotQueryTable],
"LLAttrBlobData" )
apiError = recordset
end

retVal.ok = ok
retVal.errMsg = errMsg
retVal.apiError = apiError

retVal.attrData = attrData

return retval
end

sEND
o {'pat26062017000001::OpenExportFiles',&&oe::Export}
N OpenExportFiles
f OpenExportFile
s

/**
* This function will open the export file
*
* @param {Object} prgCtx
* @param {String} filename
* @param {Integer} seq
*
* @return {Assoc}
* @returnFeature {Boolean} ok
* @returnFeature {String} errMsg
*
*/

function Assoc OpenExportFiles( \


Object prgCtx, \
String filename, \
Integer seq )

Assoc retval = Assoc.CreateAssoc()


Assoc result
CAPILOGIN clogin = prgCtx.fDbConnect.fLogin
Assoc config
String workingDirectory, logDirectory
String logFile, exportFile

//MT-01 SEB OBJECT EXPORTER FILE EXTENSION CHANGES TO


XML
//String exportFilename = Str.Format( "%1_
%2.txt", filename, $OE.Utils.PadNumber(seq,10) )
String exportFilename = Str.Format( "%1_
%2.xml", filename, $OE.Utils.PadNumber(seq,10) )

retval.ok = TRUE
retval.errMsg = ""

// get the working directory from the config data

result = $OE.Settings.Get( clogin )

if ( result.ok )

config = result.config

if ( IsFeature( config, "WorkingDirectory" ) \


&&
IsDefined( config.WorkingDirectory ) \
&& Length( config.WorkingDirectory ) )

workingDirectory =
config.WorkingDirectory

if ( workingDirectory[:-2] !=
File.Separator() )

workingDirectory =
Str.Format( "%1%2", workingDirectory, File.Separator() )
end

exportFile = Str.Format( "%1%2",


workingDirectory, exportFilename )

else
retval.ok = FALSE
retval.errMsg =
Str.Format( [OE_ERRMSG.ValueIsNotDefined], "WorkingDirectory" )
return retval
end

else
retval.ok = FALSE
retval.errMsg = result.errMsg
return retval
end

// open the export file in append mode

.fExportFilePointer = File.Open ( exportFile,


File.AppendMode )

if ( IsNotError( .fExportFilePointer ) )
// write the opening <export> tag

._WriteStartTag( Assoc.CreateAssoc(), "import",


"" )

else
retval.ok = FALSE
retval.errMsg =
Str.Format( [OE_ERRMSG.CouldNotOpenFile], exportFile )
return retval
end

return retval

end

sEND

You might also like