Skip to content

Commit

Permalink
Merge pull request #1098 from linea-it/develop
Browse files Browse the repository at this point in the history
v.0.22
  • Loading branch information
linea-relmanager authored Mar 23, 2018
2 parents fc08775 + 58401db commit 3294d8a
Showing 1,692 changed files with 116,978 additions and 53 deletions.
2 changes: 1 addition & 1 deletion api/product/admin.py
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ class PermissionAdmin(admin.ModelAdmin):


class ProductRelatedAdmin(admin.ModelAdmin):
list_display = ('id', 'prl_product', 'prl_related', 'prl_cross_identification',)
list_display = ('id', 'prl_product', 'prl_related', 'prl_relation_type', 'prl_cross_identification',)


class FiltersetdAdmin(admin.ModelAdmin):
20 changes: 20 additions & 0 deletions api/product/migrations/0008_productrelated_prl_relation_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2018-03-15 16:15
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('product', '0007_product_prd_is_permanent'),
]

operations = [
migrations.AddField(
model_name='productrelated',
name='prl_relation_type',
field=models.CharField(choices=[('join', 'Join'), ('input', 'Input')], default='join', max_length=10, verbose_name='Relation Type'),
),
]
15 changes: 15 additions & 0 deletions api/product/models.py
Original file line number Diff line number Diff line change
@@ -199,12 +199,27 @@ class ProductContentSetting(models.Model):


class ProductRelated(models.Model):

relation_types = (
# join quando um produto esta ligado ao outro atraves de uma property com ucd meta.id.cross
('join', 'Join'),
# input quando um produto foi usado como input na geracao do outro, o related representa o input.
('input', 'Input'),
)

prl_product = models.ForeignKey(
Product, on_delete=models.CASCADE, verbose_name='Product'
)
prl_related = models.ForeignKey(
Product, related_name="relateds", on_delete=models.CASCADE, verbose_name='Related Product'
)
prl_relation_type = models.CharField(
max_length=10,
choices=relation_types,
default='join',
verbose_name='Relation Type'
)

prl_cross_identification = models.ForeignKey(
ProductContent, on_delete=models.CASCADE, verbose_name='Cross Identification', default=None,
null=True, blank=True, help_text="Foreign key between the product and the related product",
21 changes: 17 additions & 4 deletions api/product/serializers.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
import logging
import os
import time
from urllib.parse import urljoin

import humanize
from django.contrib.auth.models import User
@@ -42,6 +43,8 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):

tablename = serializers.SerializerMethodField()

productlog = serializers.SerializerMethodField()

class Meta:
model = Product

@@ -63,7 +66,8 @@ class Meta:
'prl_related',
'prl_cross_identification',
'prl_cross_property',
'tablename'
'tablename',
'productlog'
)

def get_pcl_name(self, obj):
@@ -98,21 +102,21 @@ def get_prd_filter(self, obj):

def get_prl_related(self, obj):
try:
related = ProductRelated.objects.get(prl_product=obj.pk)
related = ProductRelated.objects.get(prl_product=obj.pk, prl_relation_type="join")
return related.prl_related.pk
except:
return None

def get_prl_cross_identification(self, obj):
try:
related = ProductRelated.objects.get(prl_product=obj.pk)
related = ProductRelated.objects.get(prl_product=obj.pk, prl_relation_type="join")
return related.prl_cross_identification.pk
except:
return None

def get_prl_cross_property(self, obj):
try:
related = ProductRelated.objects.get(prl_product=obj.pk)
related = ProductRelated.objects.get(prl_product=obj.pk, prl_relation_type="join")
return related.prl_cross_identification.pcn_column_name.lower()
except:
return None
@@ -126,6 +130,14 @@ def get_tablename(self, obj):
except:
return None

def get_productlog(self, obj):
try:
site = obj.prd_process_id.epr_site.sti_url
return urljoin(site, "VP/getViewProcessCon?process_id=%s" % obj.prd_process_id.epr_original_id)

except:
return None


class FileSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
@@ -593,6 +605,7 @@ class Meta:
'id',
'prl_product',
'prl_related',
'prl_relation_type',
'prl_cross_identification',
'prl_cross_name'
)
16 changes: 15 additions & 1 deletion api/product/views.py
Original file line number Diff line number Diff line change
@@ -451,6 +451,17 @@ def get_display_content(self, request):
return Response(ordered)


class ProductRelatedFilter(django_filters.FilterSet):
prd_class = django_filters.MethodFilter()

class Meta:
model = ProductRelated
fields = ['prl_product', 'prl_related', 'prl_relation_type', 'prl_cross_identification', 'prd_class']

def filter_prd_class(self, queryset, value):
return queryset.filter(prl_related__prd_class__pcl_name=str(value))


class ProductRelatedViewSet(viewsets.ModelViewSet):
"""
@@ -459,7 +470,10 @@ class ProductRelatedViewSet(viewsets.ModelViewSet):

serializer_class = ProductRelatedSerializer

filter_fields = ('prl_product', 'prl_related', 'prl_cross_identification')
filter_backends = (filters.DjangoFilterBackend, )

filter_class = ProductRelatedFilter



class ProductContentAssociationViewSet(viewsets.ModelViewSet):
84 changes: 72 additions & 12 deletions api/product_register/ImportProcess.py
Original file line number Diff line number Diff line change
@@ -29,12 +29,14 @@ def start_import(self, request):
'request': request
}

# Esta propriedade e usada apenas se no mesmo processo tiver 2 produtos um de Galaxy Cluster e um de Cluster Member
# Guarda um dict com a classe de cada produto e a intancia do ProductModel
# ex:
# dict({
# 'galaxy_clusters': ProductModel
# 'cluster_memebers': ProductModel
# 'vac': ProductModel
# })
self._gc_cm = dict({})
self._products_classes = dict({})

# Ticket server para identificar o owner do processo quando
# o processo esta sendo importado por outro sistema, nesse caso o user logado
@@ -167,6 +169,7 @@ def process_tags(self, process, tags, add_release=True):
except Tag.DoesNotExist:
raise Exception("this Tag '%s' is not valid." % tag_name)


def process_export(self, process, data):

# Associar Process a Export
@@ -194,10 +197,16 @@ def import_products(self, data):
else:
raise Exception("Product Type '%s' not implemented yet." % product.get('type'))

print(self._products_classes)

# Verificar a classe dos produtos se for galaxy cluster ou cluster members deve ser feita a ligacao entre as 2
if ('galaxy_clusters' in self._gc_cm) and ('cluster_members' in self._gc_cm):
if ('galaxy_clusters' in self._products_classes) and ('cluster_members' in self._products_classes):
self.link_galaxy_cluster_with_cluster_members()

# Verificar a classe dos produtos se for galaxy cluster e vac da classe vac_cluster
if ('galaxy_clusters' in self._products_classes) and ('vac_cluster' in self._products_classes):
self.link_galaxy_cluster_with_vac_cluster()

# =============================< CATALOG >=============================
def register_catalog(self, data):
"""
@@ -244,14 +253,43 @@ def register_catalog(self, data):
else:
date = datetime.now()


# Verificar se o process id do produto e igual ao proccess id do external_proccess
# TODO esta etapa deve ser substituida com a implementacao de import inputs ou provenance
if (self.process.epr_original_id != str(data.get("process_id"))):
# Se for diferente cria um novo external proccess para ser associado ao producto.
product_process, created = ExternalProcess.objects.update_or_create(
epr_site=self.site,
epr_owner=self.owner,
epr_name=data.get('pipeline', None),
epr_original_id=data.get('process_id', None),
defaults={
"epr_username": self.owner.username,
}
)

if product_process:

add_release = True
# Associar um Release ao Processo
if 'releases' in data and len(data.get('releases')) > 0:
self.process_release(product_process, data.get('releases'))
add_release = False

if 'fields' in data and len(data.get('fields')) > 0:
self.process_tags(product_process, data.get('fields'), add_release)

else:
product_process = self.process

product, created = Catalog.objects.update_or_create(
prd_owner=self.owner,
prd_name=data.get('name').replace(' ', '_').lower(),
tbl_database=data.get('database', None),
tbl_schema=data.get('schema', None),
tbl_name=data.get('table'),
defaults={
"prd_process_id": self.process,
"prd_process_id": product_process,
"prd_class": cls,
"prd_display_name": data.get('display_name'),
"prd_product_id": data.get('product_id', None),
@@ -280,9 +318,9 @@ def register_catalog(self, data):
# Registar as colunas do catalogo
self.register_catalog_content(product, data, created)

# se um processo tiver mais de um produto e eles forem galaxy_clusters e cluster_members
if (product.prd_class.pcl_name == 'galaxy_clusters') or (product.prd_class.pcl_name == 'cluster_members'):
self._gc_cm[product.prd_class.pcl_name] = product
# guarda a classe do produto e a instancia de ProductModel
self._products_classes[product.prd_class.pcl_name] = product


return True
else:
@@ -440,29 +478,51 @@ def link_galaxy_cluster_with_cluster_members(self):
e necessario que o produto de members tenha uma propriedade com ucd meta.id.cross.
:return:
"""

gc = self._gc_cm.get('galaxy_clusters')
cm = self._gc_cm.get('cluster_members')
gc = self._products_classes.get('galaxy_clusters')
cm = self._products_classes.get('cluster_members')

# descobrir a propriedade que tem a associacao de cross_identification no produto de cluster members
try:
cross_identification = ProductContent.objects.get(pcn_product_id=cm.pk, pcn_ucd='meta.id.cross')

prd_related = ProductRelated.objects.update_or_create(
prl_product=gc,
prl_related=cm,
defaults={
"prl_related": cm,
"prl_relation_type": "join",
"prl_cross_identification": cross_identification
}
)


except ProductContent.DoesNotExist:
raise Exception(
"this cluster members product %s does not have a property with ucd meta.id.cross to be associated with "
"the galaxy cluster product." % cm.prd_display_name)


def link_galaxy_cluster_with_vac_cluster(self):
"""
Este metodo e especifico para o processo de WAZP.
caso o processo tenha galaxy_cluster, cluster_members e vac_cluster
o vac na verdade e um imput mais ate este momento nao foi definido um metodo para registrar inputs de processos.
quando houver uma forma de importar os imputs este metodo devera ser removido.
:return:
"""

gc = self._products_classes.get('galaxy_clusters')
vc = self._products_classes.get('vac_cluster')

# Criar uma relacao entre o produto de galaxy cluster e o vac que foi usado como input
prd_related = ProductRelated.objects.update_or_create(
prl_product=gc,
prl_related=vc,
defaults={
"prl_relation_type": "input",
"prl_cross_identification": None
}
)


# =============================< MAP >=============================
def register_map(self, data):
if not self.db:
1 change: 1 addition & 0 deletions apps/catalog_builder
1 change: 1 addition & 0 deletions apps/dynamicform
Loading

0 comments on commit 3294d8a

Please sign in to comment.