Beispiel #1
0
def update_service(old: Service, new: Service):
    """ Overwrites existing service (old) with newer content (new).

    Database related information like id, created_by, and so on is saved before and written back after overwriting.

    Args:
        old (Service): The existing metadata, that shall be overwritten
        new (Service): The new metadata that is used for overwriting
    Returns:
         old (Service): The overwritten metadata
    """
    # reset update candidate
    new.is_update_candidate_for = None

    # save important persistance information
    _id = old.id
    created_by = old.created_by
    created_on = old.created
    published_for = old.published_for
    md = old.metadata  # metadata is expected to be updated already at this point. Therefore we need to keep it!
    activated = old.is_active

    # overwrite old information with new one
    old = deepcopy(new)
    old.id = _id
    old.created = created_on
    old.created_by = created_by
    old.published_for = published_for
    old.metadata = md
    old.is_active = activated

    old.last_modified = timezone.now()
    return old
Beispiel #2
0
    def _create_additional_records(self, service: Service, metadata: Metadata,
                                   group: MrMapGroup):
        """ Creates additional records like linked service metadata, keywords or MimeTypes/Formats

        Args:
            service (Service): The service record
            metadata (Metadata): THe metadata record
        Returns:

        """
        # Keywords
        for kw in self.service_identification_keywords:
            if kw is None:
                continue
            keyword = Keyword.objects.get_or_create(keyword=kw)[0]
            metadata.keywords.add(keyword)

        # MimeTypes / Formats
        for operation, formats in self.operation_format_map.items():
            for format in formats:
                mime_type = MimeType.objects.get_or_create(operation=operation,
                                                           mime_type=format,
                                                           created_by=group)[0]
                metadata.formats.add(mime_type)

        # Check for linked service metadata that might be found during parsing
        if self.linked_service_metadata is not None:
            service.linked_service_metadata = self.linked_service_metadata.to_db_model(
                MetadataEnum.SERVICE.value, created_by=metadata.created_by)
            metadata.add_metadata_relation(
                to_metadata=service.linked_service_metadata,
                relation_type=MetadataRelationEnum.VISUALIZES.value,
                origin=ResourceOriginEnum.CAPABILITIES.value)
Beispiel #3
0
def new(request):
    # Restrict To within SoC
    print ip_address_processor(request)['ip_address']

    if request.method == 'POST':
        form = ServiceForm(request.POST, request.FILES)
        if form.is_valid():
            handle_uploaded_file(request.FILES['file'])
            name = form.cleaned_data['name']
            desc = form.cleaned_data['description']
            command = form.cleaned_data['command']
            location = '/tmp/' + request.FILES['file'].name

            aService = Service(name=name, description=desc, command=command, location=location)
            aService.save()
            # Run the service in the background
            messages.add_message(request, messages.SUCCESS, 'Successfully Created')
            return HttpResponseRedirect('/service/')
    else:
        form = ServiceForm()
    return render(request, 'service/new.html', {'form': form})
Beispiel #4
0
    def _create_layer_record(self, metadata: Metadata, parent_service: Service,
                             group: MrMapGroup, parent: Layer):
        """ Creates a Layer record from the OGCLayer object

        Args:
            metadata (Metadata): The layer's metadata object
            parent_service (Service): The parent Service object
            group (MrMapGroup): The owner/creator group
            parent (Layer): The parent layer object
        Returns:
             layer (Layer): The persisted layer object
        """
        # Layer
        layer = Layer()
        layer.metadata = metadata
        layer.identifier = self.identifier
        layer.service_type = parent_service.service_type
        layer.parent = parent
        layer.parent_service = parent_service
        layer.is_queryable = self.is_queryable
        layer.is_cascaded = self.is_cascaded
        layer.registered_by = group
        layer.is_opaque = self.is_opaque
        layer.scale_min = self.capability_scale_hint.get("min")
        layer.scale_max = self.capability_scale_hint.get("max")
        layer.bbox_lat_lon = metadata.bounding_geometry
        layer.created_by = group
        layer.published_for = parent_service.published_for
        layer.parent_service = parent_service

        # Save model so M2M relations can be used
        layer.save()

        operation_urls = [
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_CAPABILITIES.value,
                url=self.get_capabilities_uri_GET,
                method="Get")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_CAPABILITIES.value,
                url=self.get_capabilities_uri_POST,
                method="Post")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_FEATURE_INFO.value,
                url=self.get_feature_info_uri_GET,
                method="Get")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_FEATURE_INFO.value,
                url=self.get_feature_info_uri_POST,
                method="Post")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.DESCRIBE_LAYER.value,
                url=self.describe_layer_uri_GET,
                method="Get")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.DESCRIBE_LAYER.value,
                url=self.describe_layer_uri_POST,
                method="Post")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_STYLES.value,
                url=self.get_styles_uri_GET,
                method="Get")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_STYLES.value,
                url=self.get_styles_uri_POST,
                method="Post")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_LEGEND_GRAPHIC.value,
                url=self.get_legend_graphic_uri_GET,
                method="Get")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_LEGEND_GRAPHIC.value,
                url=self.get_legend_graphic_uri_POST,
                method="Post")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_MAP.value,
                url=self.get_map_uri_GET,
                method="Get")[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_MAP.value,
                url=self.get_map_uri_POST,
                method="Post")[0],
        ]

        layer.operation_urls.add(*operation_urls)

        # If parent layer is a real layer, we add the current layer as a child to the parent layer
        if layer.parent is not None:
            layer.parent.children.add(layer)

        if self.style is not None:
            self.style.layer = layer
            self.style.save()

        if parent_service.root_layer is None:
            # no root layer set yet
            parent_service.root_layer = layer
            parent_service.save()

        layer.save()

        return layer
Beispiel #5
0
    def _create_layer_record(self, metadata: Metadata, parent_service: Service,
                             group: MrMapGroup, parent: Layer):
        """ Creates a Layer record from the OGCLayer object

        Args:
            metadata (Metadata): The layer's metadata object
            parent_service (Service): The parent Service object
            group (MrMapGroup): The owner/creator group
            parent (Layer): The parent layer object
        Returns:
             layer (Layer): The persisted layer object
        """
        # Layer
        layer = Layer()
        layer.metadata = metadata
        layer.identifier = self.identifier
        layer.service_type = parent_service.service_type
        layer.parent = parent
        layer.parent_service = parent_service
        layer.is_queryable = self.is_queryable
        layer.is_cascaded = self.is_cascaded
        layer.registered_by = group
        layer.is_opaque = self.is_opaque
        layer.scale_min = self.capability_scale_hint.get("min")
        layer.scale_max = self.capability_scale_hint.get("max")
        layer.bbox_lat_lon = metadata.bounding_geometry
        layer.created_by = group
        layer.published_for = parent_service.published_for
        layer.parent_service = parent_service

        # Save model so M2M relations can be used
        layer.save()

        operation_urls = []

        for operation, parsed_operation_url, method in self.operation_urls:
            # todo: optimize as bulk create
            try:
                operation_urls.append(
                    ServiceUrl.objects.get_or_create(operation=operation,
                                                     url=getattr(
                                                         self,
                                                         parsed_operation_url),
                                                     method=method)[0])
            except IntegrityError:
                pass

        layer.operation_urls.add(*operation_urls)

        # If parent layer is a real layer, we add the current layer as a child to the parent layer
        if layer.parent is not None:
            layer.parent.children.add(layer)

        if self.style is not None:
            self.style.layer = layer
            self.style.save()

        if parent_service.root_layer is None:
            # no root layer set yet
            parent_service.root_layer = layer
            parent_service.save()

        layer.save()

        return layer
Beispiel #6
0
    def _create_service_record(self, group: MrMapGroup,
                               orga_published_for: Organization,
                               metadata: Metadata,
                               is_update_candidate_for: Service):
        """ Creates a Service object from the OGCWebFeatureService object

        Args:
            group (MrMapGroup): The owner/creator group
            orga_published_for (Organization): The organization for which the service is published
            orga_publisher (Organization): THe organization that publishes
            metadata (Metadata): The describing metadata
        Returns:
             service (Service): The persisted service object
        """

        # Create ServiceType record if it doesn't exist yet
        service_type = ServiceType.objects.get_or_create(
            name=self.service_type.value.lower(),
            version=self.service_version.value)[0]
        service = Service()
        service.availability = 0.0
        service.is_available = False
        service.service_type = service_type
        service.published_for = orga_published_for
        service.created_by = group
        operation_urls = []
        for operation, parsed_operation_url, method in self.operation_urls:
            # todo: optimize as bulk create
            try:
                operation_urls.append(
                    ServiceUrl.objects.get_or_create(operation=operation,
                                                     url=getattr(
                                                         self,
                                                         parsed_operation_url),
                                                     method=method)[0])

            except IntegrityError:
                # empty/None url values will be ignored
                pass

        service.operation_urls.add(*operation_urls)
        service.metadata = metadata
        service.is_root = True
        service.is_update_candidate_for = is_update_candidate_for

        service.save()

        # Persist capabilities document
        service.persist_original_capabilities_doc(
            self.service_capabilities_xml)

        return service
Beispiel #7
0
def subscribe_service(request, key):
    service = Service.get(key)
    form = SubscribeForm()
    person_email_content = ''

    if request.method == 'POST':
        form = SubscribeForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            type_email = form.cleaned_data['type_email']
            if service.person_mail == True:
                person_email_content = request.POST['person_mail']

            person = Person.all().filter("person_email =", email).get()
            if person == None:
                person = Person(person_first_name=first_name,
                                person_last_name=last_name,
                                person_email=email,
                                person_is_activ=True,
                                person_type_email=type_email)
                person.put()
            else:
                person.person_is_activ = True
                person.put()

            subscr_query = Subscribe.all().filter("subscribe_user ="******""
                for dest in service.responsable:
                    user = get_object(User, dest)
                    to += render_to_string('service/subscribe_email_to.txt',
                                           {'user': user})
                message.to = to
                message.send()

            return render_to_response(request, 'service/subscribe_ok.html',
                                      {'service': service})

    return render_to_response(request, 'service/subscribe_form.html', {
        'service': service,
        'form': form
    })
Beispiel #8
0
    def _create_service_record(self, group: MrMapGroup, orga_published_for: Organization, metadata: Metadata, is_update_candidate_for: Service):
        """ Creates a Service object from the OGCWebFeatureService object

        Args:
            group (MrMapGroup): The owner/creator group
            orga_published_for (Organization): The organization for which the service is published
            orga_publisher (Organization): THe organization that publishes
            metadata (Metadata): The describing metadata
        Returns:
             service (Service): The persisted service object
        """

        # Create ServiceType record if it doesn't exist yet
        service_type = ServiceType.objects.get_or_create(
            name=self.service_type.value.lower(),
            version=self.service_version.value
        )[0]
        service = Service()
        service.availability = 0.0
        service.is_available = False
        service.service_type = service_type
        service.published_for = orga_published_for
        service.created_by = group
        operation_urls = [
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_CAPABILITIES.value,
                url=self.get_capabilities_uri_GET,
                method="Get"
            )[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_CAPABILITIES.value,
                url=self.get_capabilities_uri_POST,
                method="Post"
            )[0],

            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_FEATURE_INFO.value,
                url=self.get_feature_info_uri_GET,
                method="Get"
            )[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_FEATURE_INFO.value,
                url=self.get_feature_info_uri_POST,
                method="Post"
            )[0],

            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.DESCRIBE_LAYER.value,
                url=self.describe_layer_uri_GET,
                method="Get"
            )[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.DESCRIBE_LAYER.value,
                url=self.describe_layer_uri_POST,
                method="Post"
            )[0],

            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_STYLES.value,
                url=self.get_styles_uri_GET,
                method="Get"
            )[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_STYLES.value,
                url=self.get_styles_uri_POST,
                method="Post"
            )[0],

            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_LEGEND_GRAPHIC.value,
                url=self.get_legend_graphic_uri_GET,
                method="Get"
            )[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_LEGEND_GRAPHIC.value,
                url=self.get_legend_graphic_uri_POST,
                method="Post"
            )[0],

            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_MAP.value,
                url=self.get_map_uri_GET,
                method="Get"
            )[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_MAP.value,
                url=self.get_map_uri_POST,
                method="Post"
            )[0],

        ]

        service.operation_urls.add(*operation_urls)
        service.metadata = metadata
        service.is_root = True
        service.is_update_candidate_for=is_update_candidate_for

        service.save()

        # Persist capabilities document
        service.persist_original_capabilities_doc(self.service_capabilities_xml)

        return service
Beispiel #9
0
    def _create_service_record(self, group: MrMapGroup,
                               orga_published_for: Organization, md: Metadata,
                               is_update_candidate_for: Service):
        """ Creates a Service object from the OGCWebFeatureService object

        Args:
            group (MrMapGroup): The owner/creator group
            orga_published_for (Organization): The organization for which the service is published
            orga_publisher (Organization): THe organization that publishes
            md (Metadata): The describing metadata
        Returns:
             service (Service): The persisted service object
        """
        service = Service()
        service_type = ServiceType.objects.get_or_create(
            name=self.service_type.value.lower(),
            version=self.service_version.value)[0]

        service.service_type = service_type
        service.created_by = group
        service.published_for = orga_published_for

        service.availability = 0.0
        service.is_available = False
        service.is_root = True
        md.service = service
        service.is_update_candidate_for = is_update_candidate_for

        # Save record to enable M2M relations
        service.save()

        operation_urls = [
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_CAPABILITIES.value,
                method="Get",
                url=self.get_capabilities_uri.get("get", None))[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_CAPABILITIES.value,
                method="Post",
                url=self.get_capabilities_uri.get("post", None))[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.DESCRIBE_RECORD.value,
                method="Get",
                url=self.describe_record_uri.get("get", None))[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.DESCRIBE_RECORD.value,
                method="Post",
                url=self.describe_record_uri.get("post", None))[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_RECORDS.value,
                method="Get",
                url=self.get_records_uri.get("get", None))[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_RECORDS.value,
                method="Post",
                url=self.get_records_uri.get("post", None))[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_RECORD_BY_ID.value,
                method="Get",
                url=self.get_record_by_id_uri.get("get", None))[0],
            ServiceUrl.objects.get_or_create(
                operation=OGCOperationEnum.GET_RECORD_BY_ID.value,
                method="Post",
                url=self.get_record_by_id_uri.get("post", None))[0],
        ]
        service.operation_urls.add(*operation_urls)

        # Persist capabilities document
        service.persist_original_capabilities_doc(
            self.service_capabilities_xml)

        return service
Beispiel #10
0
def add_service(service_entry):
    print('Service:', service_entry['description'])
    category_obj = Category.objects.get(name=service_entry['category'])
    service_entry['category'] = category_obj
    item = Service(**service_entry)
    item.save()
Beispiel #11
0
    def save(self, data, element_object=None):
        if element_object == None:
            service = Service()
            uid = self.generateUID()
            service.uid = uid
        else:
            service = element_object


        uid_env = self.parseData(data, "environnement")
        environnement = self.getEnv(uid_env)

        if not environnement == None:
            service.name = self.parseData(data, "name")
            #service.label = self.parseData(data, "label")
            service.type = self.parseData(data, "type")
            service.before_install = self.parseData(data, "before_install")
            service.script = self.parseData(data, "script")
            service.after_success = self.parseData(data, "after_success")
            service.deploy = self.parseData(data, "deploy")
            service.on_branch = self.parseData(data, "on_branch")
            service.save()


            list_variables = self.parseData(data, "variables")
            for variable_uid in list_variables:
                variable_item = self.getVariable(variable_uid)
                if not variable_item == None:
                    service.variable.add(variable_item)

            list_variables_items = self.parseData(data, "variables_items")
            for var_item in list_variables_items:
                var_item_object = self.saveVariable(var_item)
                if not var_item_object == None:
                    service.variable.add(var_item_object)


            service.environnement.add(environnement)

            return { "status" : "success", "message" : "Saved", "element" :  "service", "uid" : service.uid }
        else:
            return {"status": "error", "message": "Environnement Not exist", "element" :  "service"}