Beispiel #1
0
 def _validate_obj_id(obj, system):
     if 'id' not in obj:
         raise MissingFieldException('id', 'ChangeSet')
     if type(obj['id']) is not int:
         raise InvalidTypeException('id', 'ChangeSet', int)
     if obj['id'] not in system.projects:
         raise InvalidIdException(obj['id'])
Beispiel #2
0
 def remove_dependency(self, id: int):
         if id not in self.depend_set:
                 raise InvalidIdException(id)
         self.dependencies.remove(id)
         self.depend_set.remove(id)
         parent = self.system.get_event_by_id(id)
         parent.successors.remove(id)
Beispiel #3
0
 def add_dependency(self, id: int):
         if id in self.depend_set:
                 raise DuplicateIdException(id, 'project.dependencies')
         if id not in self.system.projects:
                 raise InvalidIdException(id)
         self.dependencies.append(id)
         self.depend_set.add(id)
         parent = self.system.get_event_by_id(id)
         parent.successors.add(id)
Beispiel #4
0
 def fromJSONObj(cls, obj, system):
     cls._validate_obj(obj, system)
     id = obj.get('id', None)
     if id is None:
         raise InvalidIdException()
     result = cls(id)
     for prop in BASIC_PROPS:
         if prop in obj:
             result.__setattr__(prop, obj[prop])
     for prop in ARRAY_PROPS:
         if prop in obj:
             result.__setattr__(prop, obj[prop])
     return result
Beispiel #5
0
 def _validate_obj_prop_type(obj, system):
     for prop in BASIC_PROPS + ARRAY_PROPS:
         if prop not in obj:
             continue
         if type(obj[prop]) is not TYPES[prop]:
             raise InvalidTypeException(type(obj[prop]), prop, 'ChangeSet',
                                        TYPES[prop])
     for prop in ARRAY_PROPS:
         if prop not in obj:
             continue
         for id in obj[prop]:
             if type(id) is not int:
                 raise InvalidTypeException(type(id), 'id',
                                            'ChangeSet.' + prop,
                                            TYPES[prop])
             if id not in system.projects:
                 raise InvalidIdException(id)
Beispiel #6
0
        def _validate_obj(cls, obj, system):
                for prop in PROPS:
                        if prop not in obj:
                                raise MissingFieldException(prop, 'Project')
                for prop in PROPS:
                        if type(obj[prop]) is not TYPES[prop]:
                                raise InvalidTypeException(
                                        type(obj[prop]),
                                        prop,
                                        'Project',
                                        TYPES[prop])
                for id in obj['dependencies']:
                        if type(id) is not int:
                                raise InvalidTypeException(
                                        type(id),
                                        'id',
                                        'Project.dependencies',
                                        int)
                if obj['required'] < 1:
                        raise InvalidProgressException(obj['required'],
                                                       'required')
                if obj['required'] < obj['progress']:
                        raise InvalidProgressException(obj['progress'],
                                                       'progress')
                if not obj['counter'] and obj['required'] != 2:
                        raise InvalidProgressException(obj['required'],
                                                       'required')

                if obj['progress'] < 0:
                        raise InvalidProgressException(obj['required'],
                                                       'progress')

                for id in obj['dependencies']:
                        if id not in system.projects:
                                raise InvalidIdException(id)

                duplicate = check_duplicate_id(obj['dependencies'])
                if duplicate:
                        raise DuplicateIdException(id, 'dependencies')
Beispiel #7
0
    def validate_with_project(change_set, project):
        if change_set.required is not None and \
           change_set.progress is None:
            if project.progress > change_set.required:
                raise InvalidProgressException('required', 'ChangeSet')
        if change_set.counter is False and \
           change_set.required is None:
            if project.required != 2:
                raise InvalidProgressException('counter', 'ChangeSet')
        if change_set.required is None and \
           change_set.progress is not None:
            if project.required < change_set.progress:
                raise InvalidProgressException('progress', 'ChangeSet')

        pass
        if change_set.dependencies_add is not None:
            for id in change_set.dependencies_add:
                if id in project.depend_set:
                    raise DuplicateIdException(id, 'project.dependencies')

        if change_set.dependencies_remove is not None:
            for id in change_set.dependencies_remove:
                if id not in project.depend_set:
                    raise InvalidIdException(id)