/* provides utility methods for handling URNs and namespaces Note the need to handle internal and external URNs internal URNs: used for communication with the channel: internal: Local Development.localsc.dcname.modelName ==> translated to folders external: vc:intr:vendor.prefix.a.b.c:MyModel (no software component...) DC names should contain \ as delimiter of parts and encoded in j2ee workspace internal URN: scope.scname.dcname.model.mdl scope: Local Development / DTR scname: localsc or other SC name dcname: dc name, may be separated by / consists of vendor/prefix/rest model: model name, simple chars only external URN: vc:intr:namespace:model namespace = reverse(vendor).prefix.rest */ var MODEL_SUFFIX = "mdl"; var DC_SUFFIX = "DC"; var SC_SUFFIX = "SC"; var IMPL_SUFFIX = "_impl"; var vFoldersRef = {}; var URN_SEPARATOR = '-'; //instead of ':' var NAMESPACE_SEPARATOR = '-'; //instead of '.' var SC_SEPARATOR = '_'; function namespaceFromDC(dc) { var ns_parts = []; ns_parts[0] = ReverseVendor(dc.vendor); ns_parts[1] = dc.name.split('/').join(NAMESPACE_SEPARATOR); var namespace = ns_parts.join(NAMESPACE_SEPARATOR); return namespace; } function removeImplKey(str){ var res = str; if(str){ lstIdx = str.lastIndexOf(IMPL_SUFFIX); if(lstIdx==str.length-IMPL_SUFFIX.length)res = str.substr(0,lstIdx); } return res; } function dcProperties2fullpath(dcProperties){ var path = ''; if(dcProperties){ path = dcProperties.scVendor +'_' +dcProperties.scName+ '/' + removeImplKey(dcProperties.getName()); } return path; } function location2fullpath(location,includeName){ var path = ''; if(location && ISA(location,'core.dev:Location')){ path = location.getSCFullName()+ '/' + removeImplKey(location.getDCId())+ (includeName ? '/' + location.getDisplayName() : ''); } return path; } function ReverseVendor(vendor_name){ var vendor_parts = vendor_name.split('.'); vendor_parts.reverse(); return vendor_parts.join(NAMESPACE_SEPARATOR); } function createNodeIdFromLocation(location){ var fullNodePath = ''; if(location && ISA(location,'core.dev:Location')){ var buf = []; buf.push('.dir'); buf.push(location.getRepository()); buf.push(location.getSCFullName()); buf.push(namespaceFromDC({name:location.getDCName(), vendor:location.getDCVendor()})); if(!location.isDC())buf.push(location.getId()); fullNodePath = buf.join('.'); } return fullNodePath; } function getVFolders() { if (ISEMPTY(vFoldersRef)) { var vflds = CLASS('#NS[DCNode]').metadata.vFolders; for (var k in vflds) { vFoldersRef[vflds[k].type] = true; } } return vFoldersRef; } function getVFolderType(type) { var types = getVFolders(); for (var i in types) { if ( CLASS(type).isa(i) ) return i.substring(i.indexOf(':') + 1); } return false; } function createNode_SC(iniobj) { //create SCNode object return $ENV.createObject('#NS[SCNode]', iniobj); } function createNode_DC(iniobj) { //create DCNode object return $ENV.createObject('#NS[DCNode]', iniobj); } function createNode_SRVFolder(iniobj) { //create ServiceNode object return $ENV.createObject('#NS[ServicesNode]', iniobj); } function createNode_Model(iniobj) { //create ModelNode object return $ENV.createObject('#NS[ModelNode]',iniobj); } function InterfaceToImplementationDC(inter_dc) { return inter_dc + IMPL_SUFFIX; } function ImplementationToInterfaceDC(impl_dc) { var new_dc = impl_dc; var len = new_dc.length; if (len>5) { var suffix = new_dc.substring(len - 5, len); if (suffix == IMPL_SUFFIX) new_dc = new_dc.substring(0, len - 5); } return new_dc; } function getSoftwareComponentVendor(sc_full_name) { var vendor = ''; if ('' != sc_full_name) { //Relies on the assumption that SC vendor doesn't contain underscores var index = sc_full_name.indexOf(SC_SEPARATOR); if (index > -1) vendor = sc_full_name.substring(0, index); } return vendor; } function getSoftwareComponentName(sc_full_name) { var name = ''; if ('' != sc_full_name) { //Relies on the assumption that SC vendor doesn't contain underscores var index = sc_full_name.indexOf(SC_SEPARATOR); return sc_full_name.substring(index + 1); } return name; } function getSoftwareComponentFullName(sc_vendor, sc_name) { return sc_vendor + SC_SEPARATOR + sc_name; } function isNewModelNameValid(modelName) { // validate model name if (!modelName) { return('#TEXT[XMSG_MDL_NAME_MISSING]'); } return $ENV.isValidName(modelName, false); } /** * Return the repository node object for the argument's node * @param node - dev:TNode * @return dev:RepositoryNode */ function getRepositoryNode(node) { if (!node || !ISA(node, 'dev:TNode')) return null; var p = node; while (p && p.parentnode && !ISA(p, 'dev:RepositoryNode')) p = p.parentnode; return p; } /** * Return the SC node object for the argument's node * @param node - dev:TNode * @return dev:SCNode */ function getSCNode(node) { if (!node || !ISA(node, 'dev:TNode')) return null; var p = node; while (p && p.parentnode && !ISA(p, 'dev:SCNode')) p = p.parentnode; return p; } /** * Return the DC node object for the argument's node * @param node - dev:TNode * @return dev:DCNode */ function getDCNode(node) { if (!node || !ISA(node, 'dev:TNode')) return null; var p = node; while (p && p.parentnode && !ISA(p, 'dev:DCNode')) p = p.parentnode; return p; } function doesSharedRepositoryNodeExist() { var repositories = $ENV.getRepositories(); for (var k in repositories){ if (repositories[k].supportedOperations) { for (var i in repositories[k].supportedOperations) { if (repositories[k].supportedOperations[i] == RepositoryOperation.PARTIAL_LCM) return true; } } } return false; } /* The following 3 definitions (TYPES, UDKEYS and saveLocationToUserData) are used to save the user data*/ /////////////////////////////////////////////////////////////////////// //PUBLIC Static TYPES var TYPES = {}; TYPES.REP = "REP"; TYPES.SC = "SC"; TYPES.DC = "DC"; TYPES.MODEL = "MODEL"; function getTYPES(){ return TYPES; } /////////////////////////////////////////////////////////////////////// //PUBLIC Static user data keys var UDKEYS = {REP:'RECENTREPOSITORYKEY', SC:'RECENTFULLSCNAME', DC:'RECENTDCKEY', MODEL:'RECENTMODELID'}; function getUserDataKeys(){ return UDKEYS; } /** * Save Component current state user data */ function saveLocationToUserData(location, type) { if (!ISA(location,'dev:Location') || (location && !$ENV.isLocalRepositoryKey(location.getRepository()))) return;//saves only if location is local var ch = $ENV.channel2; var fldModel = null; var serverUserData = ch.getUserData(true) || {}; //extraction the needed data from the location which was sent var fldDC = namespaceFromDC({name: location.getDCName(), vendor: location.getDCVendor()}); var fldSC = location.getSCFullName(); var fldRep = location.getRepository(); switch (type) { case TYPES.MODEL : if (fldMDL) serverUserData[UDKEYS[TYPES.MODEL]] = fldMDL; case TYPES.DC : if (fldDC) serverUserData[UDKEYS[TYPES.DC]] = fldDC; case TYPES.SC : if (fldSC) serverUserData[UDKEYS[TYPES.SC]] = fldSC; case TYPES.REP : if (fldRep) serverUserData[UDKEYS[TYPES.REP]] = fldRep; } ch.saveUserData(serverUserData); } /////////////////////////////////////////////////////////////////////// //PUBLIC Static properties representing supported repository operations function RepositoryOperation(){} //Read only constants that represent supported repository operations //These values must match those used on VC server in VCBrowseRepositoryIntegrator.java RepositoryOperation.PARTIAL_LCM = "Partial-LCM"; RepositoryOperation.FULL_LCM = "Full-LCM"; RepositoryOperation.CAN_CREATE_SC = "Can-Create-SC"; RepositoryOperation.CANNOT_CREATE_SC = "Cannot-Create-SC"; /////////////////////////////////////////////////////////////////////// // PUBLIC Static Freestyle DC's state class function DCState(){} //Read only Constats variables represented the DC's state as they were defined by devserver DCState.SYNCED_DC = "syncedDC"; DCState.NOT_SYNCED_DC = "not-synced"; DCState.NEW_REPOSITORY_DC = "new-repositoryDC"; DCState.ADDED_TO_SOURCE_CONTROL_DC = "AddedToSourceControlDC"; DCState.DELETED_DC = "deletedDC"; DCState.LOCAL = "local"; <@doc>returns if the DC is in a synced state DCState.isSynced = function(state) { return DCState.SYNCED_DC == state || DCState.NEW_REPOSITORY_DC==state; } <@doc>returns if the DC is in a un-synced state DCState.isUnSynced = function(state) { return DCState.NOT_SYNCED_DC == state; } <@doc>returns if the DC is in a deleted state DCState.isDeleted = function(state){ return DCState.DELETED_DC == state; } <@doc>returns if the DC is in a New state DCState.isAddToSourceControl = function(state){ return state == DCState.ADDED_TO_SOURCE_CONTROL_DC; } <@doc>returns if the DC is in Local repository DCState.isLocal = function(state){ return state == DCState.LOCAL; } function getDCIcon(state) { if (DCState.isLocal(state)) return '#URL[env~skin:icons.localDC.gif]'; else if (DCState.isAddToSourceControl(state)) return '#URL[env~skin:icons.added_to_source_control_DC.gif]'; else if(DCState.isDeleted(state)) return '#URL[env~skin:icons.outdatedDC.gif]'; else if(DCState.isSynced(state)) return '#URL[env~skin:icons.synced_dc.gif]'; else if(DCState.isUnSynced(state)) return '#URL[env~skin:icons.not_synced_dc.gif]'; else{ return '#URL[env~skin:icons.not_synced_dc.gif]'; } } /////////////////////////////////////////////////////////////////////// // PUBLIC Static Freestyle Model's state class function ModelState(){} //Read only Constats variables represented the Model's state as they were defined by devserver ModelState.SYNCED_MODEL = "syncedModel"; ModelState.NOT_SYNCED_MODEL = "not-syncedModel"; ModelState.NEW_REPOSITORY_MODEL = "new-repositoryModel"; ModelState.DELETED_MODEL = "deletedModel"; <@doc>returns if the Model is in a synced state ModelState.isSynced = function(state) { return ModelState.SYNCED_MODEL == state; } <@doc>returns if the Model is in a un-synced state ModelState.isUnSynced = function(state) { return ModelState.NOT_SYNCED_MODEL == state; } <@doc>returns if the Model is in a deleted state ModelState.isDeleted = function(state){ return ModelState.DELETED_MODEL == state; } <@doc>returns if the Model is in a New state ModelState.isAddToSourceControl = function(state){ return ModelState.NEW_REPOSITORY_MODEL == state; } <@doc>returns if the object can usedt ModelState.isKnownObj = function(obj){ return (obj && (ISA(obj, '#NS[ModelNode]') || ISA(obj, '#NS[ModelProperties]'))); } <@doc>returns if the object is local ModelState.isLocal = function(obj){ if(obj && !BOOL(obj.isLocal))return false; return true; } <@doc>returns if the Model can be checked out ModelState.canCheckOutModel = function(obj){ var res = false; if(!ModelState.isLocal(obj)){ if(ModelState.isKnownObj(obj) || (('isCheckedOut' in obj) && ('checkedOutByOtherUser' in obj) && ('isCheckedOutInAnotherServer' in obj) && ('isAddToSourceControl' in obj))){ res = !(BOOL(obj.isCheckedOut) || ('' != obj.checkedOutByOtherUser) || BOOL(obj.isCheckedOutInAnotherServer) || BOOL(obj.isAddToSourceControl)); } else { #TRACE[4,"Unknown object type when calling to ModelState.canCheckOutModel, function will return default value"]; } } return res; } <@doc>returns if the Model can be checked in ModelState.canCheckInModel = function(obj){ var res = false; if(!ModelState.isLocal(obj)){ if(ModelState.isKnownObj(obj) || (('isCheckedOut' in obj) && ('isAddToSourceControl' in obj))){ res = BOOL(obj.isCheckedOut) || BOOL(obj.isAddToSourceControl); } else { #TRACE[4,"Unknown object type when calling to ModelState.canCheckInModel, function will return default value"]; } } return res; } <@doc>returns if the Model can be reverted ModelState.canRevertModel = function(obj){ var res = false; if(!ModelState.isLocal(obj)){ if(ModelState.isKnownObj(obj) || (('isAddToSourceControl' in obj) && ('isCheckedOut' in obj))){ res = !BOOL(obj.isAddToSourceControl) && BOOL(obj.isCheckedOut); } else { #TRACE[1,"Unknown object type when calling to ModelState.canRevertModel, function will return default value"]; } } return res; } <@doc>returns if the Model can be synced ModelState.canSyncModel = function(obj){ var res = false; if(!ModelState.isLocal(obj)){ if(ModelState.isKnownObj(obj) || (('isCheckedOut' in obj) && ('isAddToSourceControl' in obj) && ('isSynced' in obj))){ res = !BOOL(obj.isSynced) && !(BOOL(obj.isCheckedOut) || BOOL(obj.isAddToSourceControl)); } else { #TRACE[4,"Unknown object type when calling to ModelState.canSyncModel, function will return default value"]; } } return res; } <@doc>returns if the Model can be synced ModelState.canForceSyncModel = function(obj){ var res = false; if(!ModelState.isLocal(obj)){ if(ModelState.isKnownObj(obj) || (('isCheckedOut' in obj) && ('isAddToSourceControl' in obj) && ('isSynced' in obj))){ res = BOOL(obj.isSynced) && !(BOOL(obj.isCheckedOut) || BOOL(obj.isAddToSourceControl)); } else { #TRACE[4,"Unknown object type when calling to ModelState.canForceSyncModel, function will return default value"]; } } return res; } <@doc>returns if the Model can be refreshed ModelState.canRefreshModel = function(obj){ var res = false; if(!ModelState.isLocal(obj)){ if(ModelState.isKnownObj(obj) || (('isAddToSourceControl' in obj) && ('isCheckedOut' in obj))){ res = !(BOOL(obj.isAddToSourceControl) || BOOL(obj.isCheckedOut)); } else { #TRACE[4,"Unknown object type when calling to ModelState.canRefreshModel, function will return default value"]; } } return res; } <@doc>returns if the Model can be added to source control ModelState.canAddModelToSourceControl = function(obj){ return ModelState.isLocal(obj); } <@doc>returns if the Model can be moved to local in ModelState.canMoveToLocal = function(obj){ return BOOL(obj.isAddToSourceControl); } <@doc>returns if the Model can be refreshed ModelState.canRemoveModel = function(obj){ var res = false; if(!ModelState.isLocal(obj)){ if(ModelState.isKnownObj(obj) || (('isAddToSourceControl' in obj) && ('isCheckedOut' in obj))){ res = !(BOOL(obj.isAddToSourceControl) || BOOL(obj.isCheckedOut)); } else { #TRACE[4,"Unknown object type when calling to ModelState.canRemoveModel, function will return default value"]; } } return res; }