Beispiel #1
0
def cloneWorkspace(workspace_id):

        published_workspace = get_object_or_404(PublishedWorkSpace, id=workspace_id)
        
        workspace = published_workspace.workspace
        
        packageCloner = PackageCloner()
        
        return packageCloner.clone_tuple(workspace)
Beispiel #2
0
 def read(self, request, workspace_id):
     published_workspace = get_object_or_404(PublishedWorkSpace, id=workspace_id)
     
     workspace = published_workspace.workspace
     
     packageCloner = PackageCloner()
     
     cloned_workspace = packageCloner.clone_tuple(workspace)
     
     return HttpResponse("{'result': 'ok', 'new_workspace_id': %s}" % (cloned_workspace.id), mimetype='application/json; charset=UTF-8')
Beispiel #3
0
 def read(self, request, from_ws_id, to_ws_id):
     from_ws = get_object_or_404(WorkSpace, id=from_ws_id)
     to_ws = get_object_or_404(WorkSpace, id=to_ws_id)
     
     user = get_user_authentication(request)
     
     packageCloner = PackageCloner()
     
     to_workspace = packageCloner.merge_workspaces(from_ws, to_ws, user)
     
     return HttpResponse("{'result': 'ok', 'merged_workspace_id': %s}" % (to_workspace.id), mimetype='application/json; charset=UTF-8')
Beispiel #4
0
    def read(self, request, workspace_id):
        published_workspace = get_object_or_404(PublishedWorkSpace,
                                                id=workspace_id)

        workspace = published_workspace.workspace

        packageCloner = PackageCloner()

        cloned_workspace = packageCloner.clone_tuple(workspace)

        return HttpResponse("{'result': 'ok', 'new_workspace_id': %s}" %
                            (cloned_workspace.id),
                            mimetype='application/json; charset=UTF-8')
Beispiel #5
0
 def read(self, request, workspace_id):
     workspace = get_object_or_404(WorkSpace, id=workspace_id)
     
     packageCloner = PackageCloner()
     
     cloned_workspace = packageCloner.clone_tuple(workspace)
     
     cloned_workspace.active=False
     cloned_workspace.save()
     
     published_workspace = PublishedWorkSpace(type='CLONED', workspace=cloned_workspace)
     published_workspace.save()
     
     return HttpResponse("{'result': 'ok', 'published_workspace_id': %s}" % (published_workspace.id), mimetype='application/json; charset=UTF-8')
Beispiel #6
0
    def read(self, request, published_ws_id, to_ws_id):
        user = get_user_authentication(request)

        published_workspace = get_object_or_404(PublishedWorkSpace, id=published_ws_id)

        from_ws = published_workspace.workspace
        to_ws = get_object_or_404(WorkSpace, id=to_ws_id)

        packageCloner = PackageCloner()

        to_workspace = packageCloner.merge_workspaces(from_ws, to_ws, user)

        result = {'result': 'ok', 'workspace_id': to_workspace.id}
        return HttpResponse(json_encode(result), mimetype='application/json; charset=UTF-8')
Beispiel #7
0
def cloneWorkspace(workspace_id, user):

    published_workspace = get_object_or_404(PublishedWorkSpace, id=workspace_id)
    
    workspace = published_workspace.workspace
    
    packageCloner = PackageCloner()
    
    cloned_workspace = packageCloner.clone_tuple(workspace)
    
    cloned_workspace.creator = user
    
    cloned_workspace.save()
    
    return cloned_workspace
Beispiel #8
0
    def read(self, request, workspace_id):
        workspace = get_object_or_404(WorkSpace, id=workspace_id)

        packageCloner = PackageCloner()

        cloned_workspace = packageCloner.clone_tuple(workspace)

        cloned_workspace.active = False
        cloned_workspace.save()

        published_workspace = PublishedWorkSpace(type='CLONED',
                                                 workspace=cloned_workspace)
        published_workspace.save()

        return HttpResponse("{'result': 'ok', 'published_workspace_id': %s}" %
                            (published_workspace.id),
                            mimetype='application/json; charset=UTF-8')
Beispiel #9
0
class  WorkSpacePublisherEntry(Resource):
    @transaction.commit_on_success
    def read(self, request, workspace_id):
        return self.create(request, workspace_id)
        
    @transaction.commit_on_success
    def create(self, request, workspace_id):
        if not request.REQUEST.has_key('data'):
            return HttpResponseBadRequest(get_xml_error(_("mashup data expected")), mimetype='application/xml; charset=UTF-8')
            
        received_json = request.REQUEST['data']
        try:
            mashup = simplejson.loads(received_json) 
            if not mashup.has_key('name'):
            	raise Exception(_('Malformed mashup JSON: expecting mashup name.'))
            if not mashup.has_key('vendor'):
                raise Exception(_('Malformed mashup JSON: expecting mashup vendor.'))
            if not mashup.has_key('version'):
                raise Exception(_('Malformed mashup JSON: expecting mashup version.'))

        except Exception, e:
            transaction.rollback()
            msg = _("mashup cannot be published: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
        
        workspace = get_object_or_404(WorkSpace, id=workspace_id)
        
        user = get_user_authentication(request)
        
        packageCloner = PackageCloner()
        
        cloned_workspace = packageCloner.clone_tuple(workspace)
        
        #Genrating info of new workspace
        vendor = mashup.get('vendor')
        name = mashup.get('name')
        version = mashup.get('version')
        author = mashup.get('author')
        email = mashup.get('email')
        description = mashup.get('description') + " \n " +get_workspace_description(workspace)
        imageURI = mashup.get('imageURI')
        wikiURI = mashup.get('wikiURI')
        
        # set default values if the variable is empty
        if imageURI == "":
            imageURI = 'http://share.skype.com/sites/devzone/headshot_mashup.jpg'
        if wikiURI == "":
            wikiURI = 'http://trac.morfeo-project.org/trac/ezwebplatform/wiki/Mashup'
        if author == "":
            author = user.username
        try:
            cloned_workspace.active=False
            cloned_workspace.vendor = vendor
            cloned_workspace.name = name
            cloned_workspace.version = version
            cloned_workspace.author = author
            cloned_workspace.mail = email
            cloned_workspace.description = description
            cloned_workspace.imageURI = imageURI
            cloned_workspace.wikiURI = wikiURI
            cloned_workspace.save()
            published_workspace = PublishedWorkSpace(type='CLONED', workspace=cloned_workspace, author=author, 
                                                     mail=email, vendor=vendor, 
                                                     name=name, version=version, description=description,
                                                     imageURI=imageURI, wikiURI=wikiURI)
            
            published_workspace.save()
        except IntegrityError, e:
            transaction.rollback()
            msg = _("mashup cannot be published: ") + "duplicated mashup"
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Beispiel #10
0
class WorkSpacePublisherEntry(Resource):
    @transaction.commit_on_success
    def read(self, request, workspace_id):
        return self.create(request, workspace_id)

    @transaction.commit_on_success
    def create(self, request, workspace_id):
        if 'data' not in request.REQUEST:
            return HttpResponseBadRequest(
                get_xml_error(_("mashup data expected")),
                mimetype='application/xml; charset=UTF-8')

        received_json = request.REQUEST['data']
        try:
            mashup = simplejson.loads(received_json)
            if 'name' not in mashup:
                raise Exception(
                    _('Malformed mashup JSON: expecting mashup name.'))
            if 'name' not in mashup:
                raise Exception(
                    _('Malformed mashup JSON: expecting mashup vendor.'))
            if 'version' not in mashup:
                raise Exception(
                    _('Malformed mashup JSON: expecting mashup version.'))

        except Exception, e:
            transaction.rollback()
            msg = _("mashup cannot be published: ") + unicode(e)

            raise TracedServerError(e, mashup, request, msg)

        workspace = get_object_or_404(WorkSpace, id=workspace_id)

        user = get_user_authentication(request)

        #Cloning original workspace!
        packageCloner = PackageCloner()

        cloned_workspace = packageCloner.clone_tuple(workspace)

        #Generating info of new workspace
        vendor = mashup.get('vendor')
        name = mashup.get('name')
        version = mashup.get('version')
        email = mashup.get('email')

        description = mashup.get('description')
        if (description):
            description = description + " \n " + get_workspace_description(
                workspace)
        else:
            description = get_workspace_description(workspace)

        author = mashup.get('author')
        if (not author):
            author = user.username

        imageURI = mashup.get('imageURI')
        if (not imageURI):
            imageURI = settings.MEDIA_URL + 'images/headshot_mashup.jpg'

        wikiURI = mashup.get('wikiURI')
        if (not wikiURI):
            wikiURI = 'http://trac.morfeo-project.org/trac/ezwebplatform/wiki/Mashup'

        organization = mashup.get('organization')
        if (not organization):
            organization = ''

        readOnly = mashup.get('readOnly')
        if (not readOnly):
            readOnly = False

        contratable = mashup.get('contratable')
        if (not contratable):
            contratable = False

        #branding elements
        if mashup.get('noBranding'):
            #use an empty branding
            branding, created = Branding.objects.get_or_create(
                logo=None, viewer_logo=None)

        else:
            logo = mashup.get('logo')
            viewer_logo = mashup.get('viewerLogo')
            link = mashup.get('link')

            if (logo or viewer_logo):
                #create a new branding
                branding = Branding(logo=logo,
                                    viewer_logo=viewer_logo,
                                    link=link)
                branding.save()

            else:
                #wait for the default branding
                branding = None

        try:
            cloned_workspace.name = name
            cloned_workspace.creator = user
            cloned_workspace.setReadOnlyFields(readOnly)
            cloned_workspace.branding = branding
            cloned_workspace.save()
            published_workspace = PublishedWorkSpace(
                type='CLONED',
                workspace=cloned_workspace,
                author=author,
                mail=email,
                vendor=vendor,
                name=name,
                version=version,
                description=description,
                imageURI=imageURI,
                wikiURI=wikiURI,
                organization=organization,
                contratable=contratable)

            published_workspace.save()
        except IntegrityError, e:
            transaction.rollback()
            msg = _("mashup cannot be published: duplicated mashup")

            raise TracedServerError(e, workspace_id, request, msg)