fileDescriptor -view issue

Hi team,

In view, we have added file Descriptor property. But file Descriptor id or any related things to the file Descriptor didn’t come in the response .

FileDiscriptor

1 Like

Hi,
What do you mean by “didn’t come in the response”?
You mean response from the REST API?

1 Like

Hi Alex !
Yeah, in REST API response we didn’t get any response values like file name, size ,extension for the fileDescriptor property…

<![CDATA[select u from saas_Project u where u.id = :projectId]]>

This is the query we have used in our code. In project entity we have file attachment. So in that entity we have added file descriptor in the view . But when we access the REST API ,in the response we didn’t get any values regarding file descriptor… How we can get the file descriptor values in the REST API response?

Hi.
In order for the list of entities to contain not only simple properties of the Project entity but also information about the attachment files you must specify the view as the request parameter. This is the view you already created and it will be used for loading entities. See the example here.

Regards,
Natalia.

1 Like

Hi Natalia,

This is the code we have in rest-queries.xml file.

<query entity="saas_Project"
           name="loadProjectDetails"
           view="projectDetails">
        <jpql>
            <![CDATA[select u from saas_Project u where u.id = :projectId order by u.createTs desc]]>
        </jpql>
        <params>
            <param name="projectId"
                   type="java.util.UUID"/>
        </params>
    </query>

In this, under the projectDetails view we have added fileDescriptor property.

image

But in the response from the REST API, we didn’t get any values for the fileDescriptor property…

image

For that we need clarification… How can we get that descriptor property values from the REST API response…?

Which version of the platform do you use?

1 Like

Hi Natalia,
We are using platform version 7.2.7…

Are you sure that you uploaded files to the entity?
I’ve tried to reproduce your problem and this is my response. If file attachment attributes do not contain files, nothing has shown:

image

If file attachment attributes do contain files, it will be in response

image

1 Like

Maybe you could share a small project in order to help us investigate the problem?

1 Like

In above pic i took the attachementfiles ID:(090ed185-a6f0-7bb5-70cc-85021cfd7dc7)

As you mentioned before we are used view in the API by passing the attachment id ,we can able to see the file descriptor details. (http://localhost:8080/app/rest/v2/entities/saas_ProjectAttachment/090ed185-a6f0-7bb5-70cc-85021cfd7dc7?view=projectAttachmentDetails)

But we cant able to fetch fileDescriptor in the first pic…

Pls find the project entity and attachment


package com.company.saas.entity;

import com.company.saas.bean.ProjectBean;
import com.company.saas.util.DateUtil;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.core.entity.annotation.Lookup;
import com.haulmont.cuba.core.entity.annotation.LookupType;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Table(name = "SAAS_PROJECT")
@Entity(name = "saas_Project")
public class Project extends StandardEntity {
    private static final long serialVersionUID = -886992529158567092L;

    @Length(message = "Project Name should be min= 3 char max=50", min = 3, max = 50)
    @NotNull
    @Column(name = "PROJECT_NAME", nullable = false, length = 50)
    protected String projectName;

    @Length(message = "Short Form Should be 3 char", min = 3, max = 3)
    @NotNull
    @Column(name = "SHORT_FORM", nullable = false, length = 3)
    protected String shortForm;

    @Column(name = "PROJECT_ID", length = 50)
    protected String projectId;

    @NotNull
    @Lookup(type = LookupType.DROPDOWN, actions = {})
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "CLIENT_ID")
    protected OrgUnits client;

    @Length(message = " Project Description should be 1000 char", min = 5, max = 1000)
    @NotNull
    @Lob
    @Column(name = "PROJECT_DESCRIPTION", nullable = false)
    protected String projectDescription;

    @OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
    protected List<ProjectAttachment> attachmentFiles;

    @Temporal(TemporalType.DATE)
    @NotNull
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Column(name = "START_DATE", nullable = false)
    protected Date startDate;

    @NotNull
    @Column(name = "ESTIMATED_HOURS", nullable = false)
    protected Integer estimatedHours;

    @NotNull
    @Column(name = "PROJECT_STATUS", nullable = false)
    protected Integer projectStatus;

    @OneToMany(mappedBy = "project")
    protected List<Module> modules;

    @Temporal(TemporalType.DATE)
    @NotNull
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Column(name = "END_DATE", nullable = false)
    protected Date endDate;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PROJECT_OWNER_ID")
    protected ExtUser projectOwner;

    @OneToMany(mappedBy = "project")
    protected List<ProjectComment> comments;

    @Column(name = "GROUP_ID")
    protected UUID groupId;

    public void setGroupId(UUID groupId) {
        this.groupId = groupId;
    }

    public UUID getGroupId() {
        return groupId;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setAttachmentFiles(List<ProjectAttachment> attachmentFiles) {
        this.attachmentFiles = attachmentFiles;
    }

    public List<ProjectAttachment> getAttachmentFiles() {
        return attachmentFiles;
    }

    public List<ProjectComment> getComments() {
        return comments;
    }

    public void setComments(List<ProjectComment> comments) {
        this.comments = comments;
    }

    public void setProjectOwner(ExtUser projectOwner) {
        this.projectOwner = projectOwner;
    }

    public ExtUser getProjectOwner() {
        return projectOwner;
    }

    public List<Module> getModules() {
        return modules;
    }

    public void setModules(List<Module> modules) {
        this.modules = modules;
    }

    public ProjectStatus getProjectStatus() {
        return projectStatus == null ? null : ProjectStatus.fromId(projectStatus);
    }

    public void setProjectStatus(ProjectStatus projectStatus) {
        this.projectStatus = projectStatus == null ? null : projectStatus.getId();
    }

    public Integer getEstimatedHours() {
        return estimatedHours;
    }

    public void setEstimatedHours(Integer estimatedHours) {
        this.estimatedHours = estimatedHours;
    }

    public String getProjectDescription() {
        return projectDescription;
    }

    public void setProjectDescription(String projectDescription) {
        this.projectDescription = projectDescription;
    }

    public OrgUnits getClient() {
        return client;
    }

    public void setClient(OrgUnits client) {
        this.client = client;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public String getShortForm() {
        return shortForm;
    }

    public void setShortForm(String shortForm) {
        this.shortForm = shortForm;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public Project() {
    }

    public Project(OrgUnits client, ProjectBean p, ExtUser user) {
        this.projectName = p.getProjectName();
        this.shortForm = p.getShortForm().toUpperCase();
//        this.projectId = projectId;
        this.client = client;
        this.projectDescription = p.getProjectDescription();
        this.startDate = DateUtil.getDateInCustomFormat(p.getStartDate(), "dd-MM-yyyy");
        this.estimatedHours = p.getEstimatedHours();
        this.projectStatus = Integer.parseInt(p.getProjectStatus());
        this.endDate = DateUtil.getDateInCustomFormat(p.getEndDate(), "dd-MM-yyyy");
        this.projectOwner = user;
    }
    public void setProject(OrgUnits client, ProjectBean p, ExtUser user) {
        this.projectName = p.getProjectName();
        this.shortForm = p.getShortForm().toUpperCase();
        this.projectId = p.getProjectId();
        this.client = client;
        this.projectDescription = p.getProjectDescription();
        this.startDate = DateUtil.getDateInCustomFormat(p.getStartDate(), "dd-MM-yyyy");
        this.estimatedHours = p.getEstimatedHours();
        this.projectStatus = Integer.parseInt(p.getProjectStatus());
        this.endDate = DateUtil.getDateInCustomFormat(p.getEndDate(), "dd-MM-yyyy");
        this.projectOwner = user;
    }
}

Here it is the Attachment Entity

/*
 * Copyright (c) 2020 saas
 */

package com.company.saas.entity;

import com.haulmont.cuba.core.entity.FileDescriptor;
import com.haulmont.cuba.core.entity.StandardEntity;

import javax.persistence.*;

@Table(name = "SAAS_PROJECT_ATTACHMENT")
@Entity(name = "saas_ProjectAttachment")
public class ProjectAttachment extends StandardEntity {
    private static final long serialVersionUID = 7266241817208209166L;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PROJECT_ID")
    protected Project project;
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FILE_DESCRIPTOR_ID")
    protected FileDescriptor fileDescriptor;

    public ProjectAttachment() {
    }

    public ProjectAttachment(Project project, FileDescriptor fileDescriptor) {
        this.project = project;
        this.fileDescriptor = fileDescriptor;
    }

    public FileDescriptor getFileDescriptor() {
        return fileDescriptor;
    }

    public void setFileDescriptor(FileDescriptor fileDescriptor) {
        this.fileDescriptor = fileDescriptor;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

}

Here it is view .xml

<view entity="saas_Project" name="projectDetails" extends="_local">
        <property name="client" view="_minimal"/>
        <property name="attachmentFiles" view="_minimal">
            <property name="project" view="_minimal"/>
            <property name="fileDescriptor" view="_minimal">
                <property name="size"/>
                <property name="sysTenantId"/>
                <property name="createTs"/>
                <property name="createdBy"/>
                <property name="updateTs"/>
                <property name="updatedBy"/>
            </property>
        </property>
        <property name="projectOwner" view="_minimal">
            <property name="email"/>
        </property>
        <property name="comments" view="_minimal">
            <property name="commentDescription"/>
            <property name="attachmentFiles" view="_minimal">
                <property name="fileDescriptor" view="_minimal">
                    <property name="size"/>
                </property>
            </property>
            <property name="project" view="_minimal"/>
            <property name="user" view="_minimal"/>
        </property>
        <property name="createTs"/>
    </view>
1 Like

Here is my demo project with entities similar to yours and the rest query. I’ve tried to reproduce your problem, but everything works fine for me. Maybe I’ve lost some important details during project creating. If so please fix it and send me an updated project. I am really looking forward to finding out the solution to your problem. demo.zip (80.9 KB)

2 Likes

Hi Natalia,
In your sample project, I checked in HSQLDB and MySql DB in HSQLDB its working fine but in MySql its not working. Could you please check your end.

HSQLDB Response
image
Mysql Response
image
MySql project attachmentTable values
image
Mysql sys file table value
imagedemoMysql.rar (769.4 KB)

Which version of the MySQL do you use?

1 Like

Just to clarify do you have a special role with access permission for all entities including FileDescriptior?

1 Like

Hi Natalia,
yes,I have,
image

image

And what about MySQL version?

1 Like

Hi Natalia,
Issue fixed. I extends the File Descriptor class file its added one column(Dtype) in the sysFile table.So,I removed the ExtFildeDescriptor class and add the permission for File Descriptor Entity now its working. Thanks for the your quick support.

1 Like