Exemple #1
0
    def validate_prospective_targets(self):
        """
        validates candidates to be added to description bundle to ascertain compatibility
        :return: validation result
        """

        result_dict = self.get_validation_result("100")

        # extract useful attributes for validation
        stages_union = dict()
        attributes_counts = list()
        benchmark_target = None
        benchmark_count = -1

        for target in self.description_targets:
            # 'focus' on target
            self.set_datafile_id(target["recordID"])

            target["attributes"] = self.get_datafile_attributes()

            # store count of attributes
            if len(target["attributes"]) not in attributes_counts:
                attributes_counts.append(len(target["attributes"]))

            if len(target["attributes"]) > benchmark_count:
                benchmark_target = target
                benchmark_count = len(target["attributes"])

            for stage in self.get_datafile_stages():
                if stage.get("is_singular_stage", False) and stage.get("ref") not in stages_union.keys():
                    stages_union[stage.get("ref")] = list()

            for su in stages_union:
                if su in target["attributes"]:
                    stages_union[su].append(target["attributes"].get(su))

        # perform metadata compatibility test
        compatible = True
        for k, v in stages_union.items():
            if len(v) > 1 and not all(x == v[0] for x in v):
                compatible = False
                result_dict = self.get_validation_result("102")
                break

        if compatible:
            # perform metadata alignment test
            if len(attributes_counts) > 1 and benchmark_target:
                # there is at least one target with metadata ahead of the rest
                result_dict = self.get_validation_result("101")
                self.set_datafile_id(benchmark_target["recordID"])
                result_dict["extra_information"] = dict(
                    summary=htags.resolve_description_data(self.get_datafile_description(),
                                                           dict()),
                    target=benchmark_target)

        return result_dict
Exemple #2
0
    def do_description_summary(self):
        record = DataFile().get_record(self.param_dict.get("target_id"))
        self.context['description'] = htags.resolve_description_data(
            record.get("description", dict()), dict())

        description_token = record.get('description_token', str())
        self.context['description']['description_record'] = dict()

        if description_token:
            description_record = Description().GET(description_token)
            if description_record:
                if not description_record["name"]:
                    description_record["name"] = "N/A"
                self.context['description']['description_record'] = dict(
                    name=description_record["name"],
                    id=str(description_record["_id"]))

        return self.context
Exemple #3
0
    def validate_bundle_candidates(self, description_bundle):
        """
        validates candidates to be added to description bundle to ascertain compatibility between
        new description targets and already existing items in the description bundle
        :param description_bundle:
        :return: validation result
        """

        # maintain a copy of the original targets
        original_targets = list(self.description_targets)

        # validating targets against one another
        result_dict = self.validate_prospective_targets()

        if description_bundle:
            # validating targets against one another as well as existing items in the bundle
            validation_code = result_dict["validation_code"]
            if validation_code in ["100", "101"]:
                # targets are compatible with one another/there may be some ahead in description metadata,
                # it should now be sufficient only to verify that
                # at least one of the targets is compatible with at least one item in the bundle

                selected_bundle_item = description_bundle[0]
                selected_target = self.description_targets[0]

                if validation_code == "101":
                    # "101": "Some targets are ahead of others! Inherit metadata?"
                    # item with most metadata is preferred here for obvious reason

                    selected_target = result_dict["extra_information"]["target"]

                description_targets = [selected_bundle_item, selected_target]
                self.set_description_targets(description_targets)

                result_dict = self.validate_prospective_targets()

                # resolve results
                if result_dict["validation_code"] == "100" and validation_code == "101":
                    result_dict = self.get_validation_result("101")
                    self.set_datafile_id(selected_target["recordID"])
                    result_dict["extra_information"] = dict(
                        summary=htags.resolve_description_data(self.get_datafile_description(),
                                                               dict()),
                        target=selected_target)
                elif result_dict["validation_code"] == "101":
                    local_target = result_dict["extra_information"]["target"]
                    if local_target["recordID"] == selected_target["recordID"]:
                        result_dict = self.get_validation_result("103")
                    elif local_target["recordID"] == selected_bundle_item["recordID"]:
                        result_dict = self.get_validation_result("101")

                    self.set_datafile_id(local_target["recordID"])
                    result_dict["extra_information"] = dict(
                        summary=htags.resolve_description_data(self.get_datafile_description(),
                                                               dict()),
                        target=local_target)

        # set data for candidates
        self.set_description_targets(original_targets)
        self.refresh_targets_data()
        result_dict["extra_information"]["candidates_data"] = self.description_targets

        return result_dict
Exemple #4
0
 def do_description_summary(self):
     self.context['description'] = htags.resolve_description_data(
         DataFile().get_record(self.param_dict.get("target_id")).get("description", dict()), dict())
     return self.context