Exemplo n.º 1
0
 def find(self, requirement_id):
     requirement = None
     with open(self.csv_file_path, 'r') as f:
         reader = csv.DictReader(f, delimiter=';')
         for row in reader:
             if row['Specification_id'] == requirement_id:
                 requirement = Requirement()
                 requirement.update(row, attributes=self.specification_map)
                 break
     return requirement
Exemplo n.º 2
0
def get_requirement_list(base_url, select, where):
    requirements = list()
    path = 'examples/specifications.csv'
    if os.path.isfile(path):
        with open(path, 'r') as f:
            reader = csv.DictReader(f, delimiter=';')
            for row in reader:
                requirement = Requirement()
                requirement.update(row, attributes=attributes)
                requirements.append(requirement)

    return requirements
Exemplo n.º 3
0
def get_requirement(base_url, specification_id):
    path = 'examples/specifications.csv'
    if os.path.isfile(path):
        with open(path, 'r') as f:
            reader = csv.DictReader(f, delimiter=';')
            for row in reader:
                if row['Specification_id'] == specification_id:
                    about = base_url.replace('selector', 'requirement')
                    requirement = Requirement(about=about)
                    requirement.update(row, attributes)

                    return requirement
Exemplo n.º 4
0
def get_requirements(base_url):
    path = 'examples/specifications.csv'
    requirements = list()
    with open(path, 'r') as f:
        reader = csv.DictReader(f, delimiter=';')

        for row in reader:
            about = base_url.replace(
                'selector', 'requirement') + '/' + row['Specification_id']
            requirement = Requirement(about=about)
            requirement.update(row, attributes=attributes)
            requirements.append(requirement)

    return requirements
Exemplo n.º 5
0
def create_requirement(data):
    if data:
        requirement = Requirement()
        if isinstance(data, Graph):
            requirement.from_rdf(data, attributes=attributes)
            identifier = [
                (s, o) for s, o in data.subject_objects(DCTERMS.identifier)
            ][0]
            if identifier:
                requirement.identifier = identifier[1]
                requirement.about = identifier[0]
        else:
            requirement.from_json(data=data, attributes=attributes)

        specification = requirement.to_mapped_object(attributes)

        if specification:
            path = 'examples/specifications.csv'
            tempfile = NamedTemporaryFile(mode='w', delete=False)

            with open(path, 'r') as f:
                reader = csv.DictReader(f, delimiter=';')
                field_names = reader.fieldnames

            with open(path, 'r') as csvfile, tempfile:
                reader = csv.DictReader(csvfile,
                                        fieldnames=field_names,
                                        delimiter=';')
                writer = csv.DictWriter(tempfile,
                                        fieldnames=field_names,
                                        delimiter=';')
                exist = False

                for row in reader:
                    if row['Specification_id'] == specification[
                            'Specification_id']:
                        exist = True
                    writer.writerow(row)

                if not exist:
                    writer.writerow(specification)

            shutil.move(tempfile.name, path)

            if exist:
                return NotModified()

            return requirement

        else:
            return NotFound()
Exemplo n.º 6
0
 def read_requirement(data):
     requirement = Requirement()
     for k, v in data.items():
         if k in CsvRequirementRepository.specification_map:
             attribute = CsvRequirementRepository.specification_map[k]['attribute']
             if hasattr(requirement, attribute):
                 attr = getattr(requirement, attribute, None)
                 if isinstance(attr, set):
                     attr.add(v if v != '' else 'Empty')
                 else:
                     setattr(requirement, attribute, v)
Exemplo n.º 7
0
    def put(self, id):
        """
        Update the status or information about a Requirement.
        For using this method to update the information for the Requirement
        it will require the ID of the Specification and the new data.
        """
        data = specification_parser.parse_args()

        if data:
            path = 'examples/specifications.csv'

            tempfile = NamedTemporaryFile(mode='w', delete=False)

            with open(path, 'r') as f:
                reader = csv.DictReader(f, delimiter=';')
                field_names = reader.fieldnames

            with open(path, 'r') as csvfile, tempfile:
                reader = csv.DictReader(csvfile,
                                        fieldnames=field_names,
                                        delimiter=';')
                writer = csv.DictWriter(tempfile,
                                        fieldnames=field_names,
                                        delimiter=';')
                modified = False

                for row in reader:
                    if row['Specification_id'] == str(id):
                        rq = Requirement()
                        rq.from_json(data, attributes)
                        row = rq.to_mapped_object(attributes)
                        row['Specification_id'] = id
                        modified = True
                    writer.writerow(row)

            shutil.move(tempfile.name, path)

            if not modified:
                return make_response('{Not Modified}', 304)

        return make_response('{}', 200)
Exemplo n.º 8
0
    def post(self):
        """
        Insert a Specification to the store converted also in a Requirement

        Use this method to create a new specification item on the store.

        Use the next example as an input


        ```
        {
          "specification_id": "X1C2V3B6",
          "product": "OSLC SDK 6",
          "project": "OSLC-Project 6",
          "title": "OSLC RM Spec 6",
          "description": "The OSLC RM Specification needs to be awesome 6",
          "source": "Ian Altman",
          "author": "Frank",
          "category": "Customer Requirement",
          "discipline": "Software Development",
          "revision": "0",
          "target_value": "1",
          "degree_of_fulfillment": "0",
          "status": "Draft"
        }
        ```
        """
        content_type = request.headers['content-type']
        logger.debug('content-type: {}'.format(content_type))
        if content_type != 'application/rdf+xml':
            data = specification_parser.parse_args()
        else:
            print('TODO - transform from rdf')

        req = Requirement()
        req.from_json(data, attributes)
        data = req.to_mapped_object(attributes)

        if data:
            path = 'examples/specifications.csv'

            tempfile = NamedTemporaryFile(mode='w', delete=False)

            with open(path, 'r') as f:
                reader = csv.DictReader(f, delimiter=';')
                field_names = reader.fieldnames

            with open(path, 'r') as csvfile, tempfile:
                reader = csv.DictReader(csvfile,
                                        fieldnames=field_names,
                                        delimiter=';')
                writer = csv.DictWriter(tempfile,
                                        fieldnames=field_names,
                                        delimiter=';')
                exist = False
                for row in reader:
                    if row['Specification_id'] == data['Specification_id']:
                        exist = True
                    writer.writerow(row)

                if not exist:
                    writer.writerow(data)

            shutil.move(tempfile.name, path)

            if exist:
                response_object = {'status': 'fail', 'message': 'Not Modified'}
                return response_object, 304

        else:
            response_object = {'status': 'fail', 'message': 'Not Found'}
            return response_object, 400

        response = make_response('', 201)
        response.headers['Location'] = req.about

        logger.debug('Adding the resource from the RM endpoint')

        return response