def parameters(self): parameters = UseCaseParameters(self.theName, self.theAuthor, self.theCode, self.theActors, self.theDescription, self.theTags, self.theEnvironmentProperties) parameters.setId(self.theUseCaseId) return parameters
def update_usecase(self, usecase, name): usecase_params = UseCaseParameters( ucName=usecase.name(), ucAuth=usecase.author(), ucCode=usecase.code(), ucActors=usecase.actors(), ucDesc=usecase.description(), tags=usecase.tags(), cProps=usecase.environmentProperties()) try: ucId = self.db_proxy.getDimensionId(name, 'usecase') if (self.db_proxy.exceptionRootObstacles(ucId) > 0): raise CairisHTTPError( status_code=http.client.BAD_REQUEST, status="Exception has root obstacles", message= "Cannot update use case while use case exception obstacles are connected to other obstacles, goals, requirements, or domain properties." ) usecase_params.setId(ucId) self.db_proxy.updateUseCase(usecase_params) except DatabaseProxyException as ex: self.close() raise ARMHTTPError(ex) except ARMException as ex: self.close() raise ARMHTTPError(ex)
def add_usecase(self, usecase): """ :type usecase: UseCase :rtype: int :raise ARMHTTPError: """ usecase_params = UseCaseParameters( ucName=usecase.name(), ucAuth=usecase.author(), ucCode=usecase.code(), ucActors=usecase.actors(), ucDesc=usecase.description(), tags=usecase.tags(), cProps=usecase.environmentProperties()) for envProp in usecase.environmentProperties(): for step in envProp.steps(): for exc in step.exceptions(): self.db_proxy.nameCheck(exc[0], 'obstacle') try: if not self.check_existing_usecase(usecase.name()): new_id = self.db_proxy.addUseCase(usecase_params) return new_id else: self.close() raise OverwriteNotAllowedHTTPError(obj_name=usecase.name()) except DatabaseProxyException as ex: self.close() raise ARMHTTPError(ex) except ARMException as ex: self.close() raise ARMHTTPError(ex)
def update_usecase(self, usecase, name): usecase_params = UseCaseParameters( ucName=usecase.name(), ucAuth=usecase.author(), ucCode=usecase.code(), ucActors=usecase.actors(), ucDesc=usecase.description(), tags=usecase.tags(), cProps=usecase.environmentProperties()) try: ucId = self.db_proxy.getDimensionId(name, 'usecase') usecase_params.setId(ucId) self.db_proxy.updateUseCase(usecase_params) except DatabaseProxyException as ex: self.close() raise ARMHTTPError(ex) except ARMException as ex: self.close() raise ARMHTTPError(ex)
def update_usecase(self, usecase, name): found_usecase = self.get_usecase_by_name(name, simplify=False) usecase_params = UseCaseParameters( ucName=usecase.name(), ucAuth=usecase.author(), ucCode=usecase.code(), ucActors=usecase.actors(), ucDesc=usecase.description(), tags=usecase.tags(), cProps=usecase.environmentProperties()) usecase_params.setId(found_usecase.id()) try: self.db_proxy.updateUseCase(usecase_params) except DatabaseProxyException as ex: self.close() raise ARMHTTPError(ex) except ARMException as ex: self.close() raise ARMHTTPError(ex)
def update_usecase(self, usecase, name): usecase_params = UseCaseParameters( ucName=usecase.name(), ucAuth=usecase.author(), ucCode=usecase.code(), ucActors=usecase.actors(), ucDesc=usecase.description(), tags=usecase.tags(), cProps=usecase.environmentProperties() ) try: ucId = self.db_proxy.getDimensionId(name,'usecase') usecase_params.setId(ucId) self.db_proxy.updateUseCase(usecase_params) except DatabaseProxyException as ex: self.close() raise ARMHTTPError(ex) except ARMException as ex: self.close() raise ARMHTTPError(ex)
def update_usecase(self, usecase, name): found_usecase = self.get_usecase_by_name(name, simplify=False) usecase_params = UseCaseParameters( ucName=usecase.name(), ucAuth=usecase.author(), ucCode=usecase.code(), ucActors=usecase.actors(), ucDesc=usecase.description(), tags=usecase.tags(), cProps=usecase.environmentProperties() ) usecase_params.setId(found_usecase.id()) try: self.db_proxy.updateUseCase(usecase_params) except DatabaseProxyException as ex: self.close() raise ARMHTTPError(ex) except ARMException as ex: self.close() raise ARMHTTPError(ex)
def setUpClass(cls): call([os.environ['CAIRIS_CFG_DIR'] + "/initdb.sh"]) cairis.core.BorgFactory.initialise() f = open(os.environ['CAIRIS_SRC'] + '/test/dataflow.json') d = json.load(f) f.close() iEnvironments = d['environments'] iep1 = EnvironmentParameters(iEnvironments[0]["theName"], iEnvironments[0]["theShortCode"], iEnvironments[0]["theDescription"]) b = Borg() b.dbProxy.addEnvironment(iep1) iRoles = d['roles'] irp = RoleParameters(iRoles[0]["theName"], iRoles[0]["theType"], iRoles[0]["theShortCode"], iRoles[0]["theDescription"], []) b.dbProxy.addRole(irp) iUseCases = d['use_cases'] ucName = iUseCases[0]["theName"] ucAuthor = iUseCases[0]["theAuthor"] ucCode = iUseCases[0]["theCode"] ucDesc = iUseCases[0]["theDescription"] ucActor = iUseCases[0]["theActor"] ucEnv = iUseCases[0]["theEnvironments"][0] ucEnvName = ucEnv["theName"] ucPre = ucEnv["thePreconditions"] ucPost = ucEnv["thePostconditions"] ss = Steps() for ucStep in ucEnv["theFlow"]: ss.append(Step(ucStep["theDescription"])) ucep = UseCaseEnvironmentProperties(ucEnvName, ucPre, ss, ucPost) iuc = UseCaseParameters(ucName, ucAuthor, ucCode, [ucActor], ucDesc, [], [ucep]) b = Borg() b.dbProxy.addUseCase(iuc) for iAsset in d['assets']: iaeps = [ AssetEnvironmentProperties( iAsset["theEnvironmentProperties"][0][0], iAsset["theEnvironmentProperties"][0][1], iAsset["theEnvironmentProperties"][0][2]) ] iap = AssetParameters(iAsset["theName"], iAsset["theShortCode"], iAsset["theDescription"], iAsset["theSignificance"], iAsset["theType"], "0", "N/A", [], [], iaeps) b.dbProxy.addAsset(iap)
def endElement(self, name): if name == 'domainproperty': p = DomainPropertyParameters(unescape(self.theName), unescape(self.theDefinition), self.theType, unescape(self.theOriginator), self.theTags) self.theDomainProperties.append(p) self.resetDomainPropertyAttributes() elif name == 'goal_environment': p = GoalEnvironmentProperties(self.theEnvironmentName, '', unescape(self.theDefinition), self.theCategory, self.thePriority, unescape(self.theFitCriterion), unescape(self.theIssue), [], [], self.theConcerns, self.theConcernAssociations) self.theEnvironmentProperties.append(p) self.resetGoalEnvironmentAttributes() elif name == 'obstacle_environment': p = ObstacleEnvironmentProperties(self.theEnvironmentName, '', unescape(self.theDefinition), self.theCategory, [], [], self.theConcerns) p.theProbability = self.theProbability p.theProbabilityRationale = unescape(self.theRationale) self.theEnvironmentProperties.append(p) self.resetObstacleEnvironmentAttributes() elif name == 'goal': p = GoalParameters(unescape(self.theName), unescape(self.theOriginator), self.theTags, self.theEnvironmentProperties) self.theGoals.append(p) self.resetGoalAttributes() elif name == 'obstacle': p = ObstacleParameters(unescape(self.theName), unescape(self.theOriginator), self.theTags, self.theEnvironmentProperties) self.theObstacles.append(p) self.resetObstacleAttributes() elif name == 'requirement': reqId = self.dbProxy.newId() r = cairis.core.RequirementFactory.build( reqId, self.theLabel, unescape(self.theName), unescape(self.theDescription), self.thePriority, unescape(self.theRationale), unescape(self.theFitCriterion), unescape(self.theOriginator), self.theType, self.theReference) self.theRequirements.append( (r, self.theReference, self.theReferenceType)) self.resetRequirementAttributes() elif name == 'exception': self.theCurrentStep.addException( (self.theExcName, self.theExcType.lower(), self.theExcValue, self.theExcCat, unescape(self.theDefinition))) elif name == 'step': self.theCurrentStep.setTags(self.theTags) self.theSteps.append(self.theCurrentStep) self.theCurrentStep = None elif name == 'usecase_environment': vProperty, vRationale = self.theCognitiveAttribute['vigilance'] saProperty, saRationale = self.theCognitiveAttribute[ 'situation awareness'] sProperty, sRationale = self.theCognitiveAttribute['stress'] wProperty, wRationale = self.theCognitiveAttribute['workload'] raProperty, raRationale = self.theCognitiveAttribute[ 'risk awareness'] p = UseCaseEnvironmentProperties( self.theEnvironmentName, unescape(self.thePreconditions), self.theSteps, unescape(self.thePostconditions), [vProperty, saProperty, sProperty, wProperty, raProperty], [vRationale, saRationale, sRationale, wRationale, raRationale]) self.theEnvironmentProperties.append(p) self.resetUseCaseEnvironmentAttributes() elif name == 'usecase': p = UseCaseParameters(self.theName, self.theAuthor, unescape(self.theCode), self.theActors, unescape(self.theDescription), self.theTags, self.theEnvironmentProperties) self.theUseCases.append(p) self.resetUseCaseAttributes() elif name == 'countermeasure': p = CountermeasureParameters(self.theName, unescape(self.theDescription), self.theType, self.theTags, self.theEnvironmentProperties) self.theCountermeasures.append(p) self.resetCountermeasureAttributes() elif name == 'mitigating_property': self.theSpDict[self.thePropertyName] = (self.thePropertyValue, unescape( self.theDescription)) self.resetMitigatingPropertyAttributes() elif name == 'countermeasure_environment': cProperty, cRationale = self.theSpDict['confidentiality'] iProperty, iRationale = self.theSpDict['integrity'] avProperty, avRationale = self.theSpDict['availability'] acProperty, acRationale = self.theSpDict['accountability'] anProperty, anRationale = self.theSpDict['anonymity'] panProperty, panRationale = self.theSpDict['pseudonymity'] unlProperty, unlRationale = self.theSpDict['unlinkability'] unoProperty, unoRationale = self.theSpDict['unobservability'] p = CountermeasureEnvironmentProperties( self.theEnvironmentName, self.theCmRequirements, self.theTargets, [ cProperty, iProperty, avProperty, acProperty, anProperty, panProperty, unlProperty, unoProperty ], [ cRationale, iRationale, avRationale, acRationale, anRationale, panRationale, unlRationale, unoRationale ], self.theCost, self.theCmRoles, self.theTaskPersonas) self.theEnvironmentProperties.append(p) self.resetCountermeasureEnvironmentAttributes() elif (name == 'target'): self.theTargets.append( Target(self.theTargetName, self.theTargetEffectiveness, unescape(self.theRationale))) self.theTargetResponses = [] elif (name == 'description'): self.inDescription = 0 elif (name == 'definition'): self.inDefinition = 0 elif name == 'fit_criterion': self.inFitCriterion = 0 elif name == 'issue': self.inIssue = 0 elif name == 'rationale': self.inRationale = 0 elif name == 'originator': self.inOriginator = 0 elif name == 'preconditions': self.inPreconditions = 0 elif name == 'postconditions': self.inPostconditions = 0
def testUseCase(self): ucName = self.iUseCases[0]["theName"] ucAuthor = self.iUseCases[0]["theAuthor"] ucCode = self.iUseCases[0]["theCode"] ucDesc = self.iUseCases[0]["theDescription"] ucActor = self.iUseCases[0]["theActor"] ucEnv = self.iUseCases[0]["theEnvironments"][0] ucEnvName = ucEnv["theName"] ucPre = ucEnv["thePreconditions"] ucPost = ucEnv["thePostconditions"] ss = Steps() for ucStep in ucEnv["theFlow"]: ss.append(Step(ucStep["theDescription"])) ucep = UseCaseEnvironmentProperties(ucEnvName,ucPre,ss,ucPost) iuc = UseCaseParameters(ucName,ucAuthor,ucCode,[ucActor],ucDesc,[],[ucep]) b = Borg() b.dbProxy.addUseCase(iuc) theUseCases = b.dbProxy.getUseCases() ouc = theUseCases[self.iUseCases[0]["theName"]] self.assertEqual(iuc.name(),ouc.name()) self.assertEqual(iuc.tags(),ouc.tags()) self.assertEqual(iuc.author(),ouc.author()) self.assertEqual(iuc.code(),ouc.code()) self.assertEqual(iuc.actors(),ouc.actors()) self.assertEqual(iuc.description(),ouc.description()) self.assertEqual(iuc.author(),ouc.author()) self.assertEqual(iuc.environmentProperties()[0].preconditions(),ouc.environmentProperties()[0].preconditions()) self.assertEqual(iuc.environmentProperties()[0].postconditions(),ouc.environmentProperties()[0].postconditions()) iuc.theName = 'Updated name' iuc.setId(ouc.id()) b.dbProxy.updateUseCase(iuc) theUseCases = b.dbProxy.getUseCases() ouc = theUseCases['Updated name'] self.assertEqual(iuc.name(),ouc.name()) self.assertEqual(iuc.tags(),ouc.tags()) self.assertEqual(iuc.author(),ouc.author()) self.assertEqual(iuc.code(),ouc.code()) self.assertEqual(iuc.actors(),ouc.actors()) self.assertEqual(iuc.description(),ouc.description()) self.assertEqual(iuc.author(),ouc.author()) self.assertEqual(iuc.environmentProperties()[0].preconditions(),ouc.environmentProperties()[0].preconditions()) self.assertEqual(iuc.environmentProperties()[0].postconditions(),ouc.environmentProperties()[0].postconditions()) b.dbProxy.deleteUseCase(ouc.id())
def endElement(self, name): if name == 'persona': p = PersonaParameters(self.theName, self.theActivities, self.theAttitudes, self.theAptitudes, self.theMotivations, self.theSkills, self.theIntrinsic, self.theContextual, self.theImage, self.isAssumptionPersona, self.theType, self.theTags, self.theEnvironmentProperties, {}) self.thePersonas.append(p) self.resetPersonaAttributes() elif name == 'persona_environment': p = PersonaEnvironmentProperties(self.theEnvironmentName, self.isDirect, self.theNarrative, self.theRoles, {'narrative': {}}) self.theEnvironmentProperties.append(p) self.resetPersonaEnvironmentAttributes() elif name == 'external_document': p = ExternalDocumentParameters(self.theName, self.theVersion, self.theDate, self.theAuthors, self.theDescription) self.theExternalDocuments.append(p) self.resetExternalDocumentAttributes() elif name == 'document_reference': p = DocumentReferenceParameters(self.theName, self.theDocument, self.theContributor, self.theExcerpt) self.theDocumentReferences.append(p) self.resetDocumentReferenceAttributes() elif name == 'concept_reference': p = ConceptReferenceParameters(self.theName, self.theConcept, self.theObject, self.theDescription) self.theConceptReferences.append(p) self.resetConceptReferenceAttributes() elif name == 'persona_characteristic': p = PersonaCharacteristicParameters( self.thePersona, self.theModalQualifier, self.theBvName, self.theDefinition, self.theGrounds, self.theWarrants, [], self.theRebuttals) self.thePersonaCharacteristics.append(p) self.resetPersonaCharacteristicAttributes() elif name == 'task_characteristic': p = TaskCharacteristicParameters(self.theTask, self.theModalQualifier, self.theDefinition, self.theGrounds, self.theWarrants, [], self.theRebuttals) self.theTaskCharacteristics.append(p) self.resetTaskCharacteristicAttributes() elif name == 'task': p = TaskParameters(self.theName, self.theCode, self.theObjective, self.isAssumptionTask, self.theAuthor, self.theTags, self.theEnvironmentProperties) self.theTasks.append(p) self.resetTaskAttributes() elif name == 'task_environment': p = TaskEnvironmentProperties( self.theEnvironmentName, self.theDependencies, self.theTaskPersonas, self.theConcerns, self.theConcernAssociations, self.theNarrative, self.theConsequences, self.theBenefits, { 'narrative': {}, 'consequences': {}, 'benefits': {} }) self.theEnvironmentProperties.append(p) self.resetTaskEnvironmentAttributes() elif name == 'exception': self.theCurrentStep.addException( (self.theExcName, self.theExcType, self.theExcValue, self.theExcCat, self.theDefinition)) elif name == 'step': self.theCurrentStep.setTags(self.theTags) self.theSteps.append(self.theCurrentStep) self.theCurrentStep = None elif name == 'usecase_environment': p = UseCaseEnvironmentProperties(self.theEnvironmentName, self.thePreconditions, self.theSteps, self.thePostconditions) self.theEnvironmentProperties.append(p) self.resetUseCaseEnvironmentAttributes() elif name == 'usecase': p = UseCaseParameters(self.theName, self.theAuthor, self.theCode, self.theActors, self.theDescription, self.theTags, self.theEnvironmentProperties) self.theUseCases.append(p) self.resetUseCaseAttributes() elif name == 'activities': self.inActivities = 0 elif name == 'attitudes': self.inAttitudes = 0 elif name == 'aptitudes': self.inAptitudes = 0 elif name == 'motivations': self.inMotivations = 0 elif name == 'skills': self.inSkills = 0 elif name == 'intrinsic': self.inIntrinsic = 0 elif name == 'contextual': self.inContextual = 0 elif name == 'narrative': self.inNarrative = 0 elif name == 'excerpt': self.inExcerpt = 0 elif name == 'description': self.inDescription = 0 elif name == 'definition': self.inDefinition = 0 elif name == 'dependencies': self.inDependencies = 0 elif name == 'objective': self.inObjective = 0 elif name == 'preconditions': self.inPreconditions = 0 elif name == 'postconditions': self.inPostconditions = 0 elif name == 'benefits': self.inBenefits = 0 elif name == 'consequences': self.inConsequences = 0
def parameters(self): parameters = UseCaseParameters(self.theName,self.theAuthor,self.theCode,self.theActors,self.theDescription,self.theTags,self.theEnvironmentProperties) parameters.setId(self.theUseCaseId) return parameters
def testUseCase(self): ucName = self.iUseCases[0]["theName"] ucAuthor = self.iUseCases[0]["theAuthor"] ucCode = self.iUseCases[0]["theCode"] ucDesc = self.iUseCases[0]["theDescription"] ucActor = self.iUseCases[0]["theActor"] ucEnv = self.iUseCases[0]["theEnvironments"][0] ucEnvName = ucEnv["theName"] ucPre = ucEnv["thePreconditions"] ucPost = ucEnv["thePostconditions"] ucAttribute = ucEnv["theAttributes"] ucRationale = ucEnv["theRationale"] ucDef = ucEnv["theDefinition"] ucAverage = ucEnv["theAverage"] ss = Steps() for ucStep in ucEnv["theFlow"]: ss.append(Step(ucStep["theDescription"])) ucep = UseCaseEnvironmentProperties(ucEnvName, ucPre, ss, ucPost, ucAttribute, ucRationale, ucDef, ucAverage) iuc = UseCaseParameters(ucName, ucAuthor, ucCode, [ucActor], ucDesc, [], [ucep]) b = Borg() b.dbProxy.addUseCase(iuc) theUseCases = b.dbProxy.getUseCases() ouc = theUseCases[self.iUseCases[0]["theName"]] self.assertEqual(iuc.name(), ouc.name()) self.assertEqual(iuc.tags(), ouc.tags()) self.assertEqual(iuc.author(), ouc.author()) self.assertEqual(iuc.code(), ouc.code()) self.assertEqual(iuc.actors(), ouc.actors()) self.assertEqual(iuc.description(), ouc.description()) self.assertEqual(iuc.author(), ouc.author()) self.assertEqual(iuc.environmentProperties()[0].preconditions(), ouc.environmentProperties()[0].preconditions()) self.assertEqual(iuc.environmentProperties()[0].postconditions(), ouc.environmentProperties()[0].postconditions()) self.assertEqual(iuc.environmentProperties()[0].attributes()[0], ouc.environmentProperties()[0].attributes()[0]) self.assertEqual(iuc.environmentProperties()[0].attributes()[1], ouc.environmentProperties()[0].attributes()[1]) self.assertEqual(iuc.environmentProperties()[0].attributes()[2], ouc.environmentProperties()[0].attributes()[2]) self.assertEqual(iuc.environmentProperties()[0].attributes()[3], ouc.environmentProperties()[0].attributes()[3]) self.assertEqual(iuc.environmentProperties()[0].attributes()[4], ouc.environmentProperties()[0].attributes()[4]) self.assertEqual(iuc.environmentProperties()[0].rationale()[0], ouc.environmentProperties()[0].rationale()[0]) self.assertEqual(iuc.environmentProperties()[0].rationale()[1], ouc.environmentProperties()[0].rationale()[1]) self.assertEqual(iuc.environmentProperties()[0].rationale()[2], ouc.environmentProperties()[0].rationale()[2]) self.assertEqual(iuc.environmentProperties()[0].rationale()[3], ouc.environmentProperties()[0].rationale()[3]) self.assertEqual(iuc.environmentProperties()[0].rationale()[4], ouc.environmentProperties()[0].rationale()[4]) self.assertEqual(iuc.environmentProperties()[0].definition(), ouc.environmentProperties()[0].definition()) self.assertEqual(iuc.environmentProperties()[0].average(), ouc.environmentProperties()[0].average()) iuc.theName = 'Updated name' iuc.setId(ouc.id()) b.dbProxy.updateUseCase(iuc) theUseCases = b.dbProxy.getUseCases() ouc = theUseCases['Updated name'] self.assertEqual(iuc.name(), ouc.name()) self.assertEqual(iuc.tags(), ouc.tags()) self.assertEqual(iuc.author(), ouc.author()) self.assertEqual(iuc.code(), ouc.code()) self.assertEqual(iuc.actors(), ouc.actors()) self.assertEqual(iuc.description(), ouc.description()) self.assertEqual(iuc.author(), ouc.author()) self.assertEqual(iuc.environmentProperties()[0].preconditions(), ouc.environmentProperties()[0].preconditions()) self.assertEqual(iuc.environmentProperties()[0].postconditions(), ouc.environmentProperties()[0].postconditions()) self.assertEqual(iuc.environmentProperties()[0].attributes()[0], ouc.environmentProperties()[0].attributes()[0]) self.assertEqual(iuc.environmentProperties()[0].attributes()[1], ouc.environmentProperties()[0].attributes()[1]) self.assertEqual(iuc.environmentProperties()[0].attributes()[2], ouc.environmentProperties()[0].attributes()[2]) self.assertEqual(iuc.environmentProperties()[0].attributes()[3], ouc.environmentProperties()[0].attributes()[3]) self.assertEqual(iuc.environmentProperties()[0].attributes()[4], ouc.environmentProperties()[0].attributes()[4]) self.assertEqual(iuc.environmentProperties()[0].rationale()[0], ouc.environmentProperties()[0].rationale()[0]) self.assertEqual(iuc.environmentProperties()[0].rationale()[1], ouc.environmentProperties()[0].rationale()[1]) self.assertEqual(iuc.environmentProperties()[0].rationale()[2], ouc.environmentProperties()[0].rationale()[2]) self.assertEqual(iuc.environmentProperties()[0].rationale()[3], ouc.environmentProperties()[0].rationale()[3]) self.assertEqual(iuc.environmentProperties()[0].rationale()[4], ouc.environmentProperties()[0].rationale()[4]) self.assertEqual(iuc.environmentProperties()[0].definition(), ouc.environmentProperties()[0].definition()) self.assertEqual(iuc.environmentProperties()[0].average(), ouc.environmentProperties()[0].average()) b.dbProxy.deleteUseCase(ouc.id())