I am trying to add category to new created article. My code is here:
ServiceContext serviceContext = ServiceContextFactory.getInstance(
JournalArticle.class.getName(),
actionRequest
);
article = JournalArticleLocalServiceUtil.addArticle(
ImporterConstants.IMPORTER_ID,
ImporterConstants.GROUP_ID,
ImporterConstants.DOC_FOLDER_ID,
titleMap,
descMap,
content,
structureID,
templateID,
serviceContext
);
AssetEntry ae = AssetEntryLocalServiceUtil.fetchEntry(
JournalArticle.class.getName(),
article.getResourcePrimKey()
); //returns AssetEntry
AssetEntryLocalServiceUtil.addAssetCategoryAssetEntry(48183, ae);
Article is created without problem, but when I try to call
AssetEntryLocalServiceUtil.addAssetCategoryAssetEntry(48183, ae)
or
AssetCategoryLocalServiceUtil.addAssetEntryAssetCategory(ae.getEntryId(), 48183)
it won't bring any results and table assetentries_assetcategories is without any changes. Number 48183 is categoryidfrom table `assetcategory.
Can you tell me where can be problem?
PS: I am using Liferay Portal Community Edition 6.2.0 CE GA1
Thanks
Try updating the article asset entry with the required category id
AssetEntry updateEntry(
long userId, long groupId, String className, long classPK,
String classUuid, long classTypeId, long[] categoryIds,
String[] tagNames, boolean visible, Date startDate, Date endDate,
Date publishDate, Date expirationDate, String mimeType,
String title, String description, String summary, String url,
String layoutUuid, int height, int width, Integer priority,
boolean sync)
throws PortalException, SystemException
assetEntryLocalService.updateEntry(
userId, entry.getGroupId(), JournalArticle.class.getName(),
entry.getEntryId(), entry.getUuid(), 0, assetCategoryIds,
assetTagNames, visible, null, null, entry.getDisplayDate(), null,
ContentTypes.TEXT_HTML, entry.getTitle(), null, summary, null, null,
0, 0, null, false);
Related
I'm running a SELECT using WHERE on gorm but the results are comming with the columns store_name and type empty(""). I have the following struct on Go:
type Store struct {
ID uint
StoreName string
Type string
Code string `gorm:"unique"`
Active bool
CreatedAt *time.Time
UpdatedAt *time.Time
}
The following database on Postgres:
CREATE TABLE IF NOT EXISTS stores
(
id BIGSERIAL PRIMARY KEY,
store_name TEXT NOT NULL,
type TEXT NOT NULL,
code TEXT NOT NULL UNIQUE,
active BOOLEAN DEFAULT true,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ
);
Im running this select right here:
var store Store
result := db.First(&stores).Where("code = ?", code)
if err := result.Error; err != nil {
return nil, err
}
return &stores, nil
Does anyone know what I may be doing wrong? All columns are returned on the SELECT except for the columns StoreName and Type. Thank you so much in advance!
You need to set the field tag if field name differs from DB column name.
Example:
StoreName string `gorm:"column:store_name"`
See this document: https://gorm.io/docs/models.html
In my Prisma schema, I have a model that looks like this:
model Document {
id String #id #default(uuid())
createdAt DateTime #default(now())
updatedAt DateTime #updatedAt
draft Boolean #default(true)
publishedDocumentNumber Int? #unique()
text String?
}
When each document is created, it is in draft mode with the value set to true. It does not have a publishedDocumentNumber until it is officially published. When I publish a document, I will update the draft value like this:
prisma.draft.update({
where: {
id: req.body.id,
},
data: {
draft: false,
}
});
Since this document is no longer a draft, I want to safely auto-increment the publishedDocumentNumber value to the previous published document's publishedDocumentNumber value + 1. I don't want to do a prisma.document.count since I could accidentally run into a collision if two documents are publish simultaneously (race condition), and they have to be unique.
Is there a better way to safely do this?
Try using serial or smallserial as described in the documentation
I'm new with Go and GORM. After generating my DB for testing, I don't see that the One To Many relationship is properly represented in Postgres.
I have created a couple of models to be migrated into Postgres, for example, these 2 specifically:
type PgPiece struct {
ID string `gorm:"primary_key"`
Name string
MinPrice float64
Likes int
Description string
Materials string
Techniques string
Width float64
Height float64
Length float64
Hours int
CreatedAt *time.Time
ModifiedAt *time.Time
IsFavorite bool
EstimatedValue float64
Owner PgUser `gorm:"foreignkey:OwnerID"`
OwnerID string
Author PgUser `gorm:"foreignkey:AuthorID"`
AuthorID string
Favorites []PgUser `gorm:"many2many:user_favorite_piece"`
Images []PgPieceImage `gorm:"foreignkey:piece_id"`
}
type PgPieceImage struct {
ID string `gorm:"primary_key"`
Url string
Position int
Width int
Height int
CreatedAt *time.Time
Piece PgPiece `gorm:"foreignkey:PieceRef"`
PieceRef string `gorm:"column:piece_id"`
}
And as result I see this in postgres for PgPieceImage
CREATE TABLE public.piece_image
(
id text COLLATE pg_catalog."default" NOT NULL,
url text COLLATE pg_catalog."default",
"position" integer,
width integer,
height integer,
created_at timestamp with time zone,
piece_id text COLLATE pg_catalog."default",
CONSTRAINT piece_image_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.piece_image
OWNER to freddy;
Why there is non FOREIGN CONSTRAINT there?
Working on grails 3 application. My domain structure is defined below:
Job{
Integer id
String title
Date publishedDate
}
JobType{
Integer id
String name
}
JobJobTypeMap{
String jobId
String jobTypeId
}
For example,
**Job**
id title
1 job1
2 job2
**JobType**
id name
1 govt
2 private
**JobJobTypeMap**
jobId jobTypeId
1 1
1 2
2 2
I need to get list of jobs (offset and max attributes and order published date descending) with particular jobType.
Kindly, don't ask me to change the domain structure.
Any suggestions would be appreciated
You are not defining properly the domain classes. You don't have to create the relation class between Job and JobType, Grails will do it automatically on you DB.
Job{
Integer id
String title
Date publishedDate
JobType jobType
}
JobType{
Integer id
String name
}
List<Job> jobs = Job.findAllByJobType(jobTypeInstance, [sort: '', order:'', max: '', offset: ''])
You have to use Grails SQL/HSQL to query the DB.
In controller
def getList() {
def params = [column:"job.title", order:'DESC', offset:0, limit:5]
Sql sql = new Sql(dataSource)
String query = """
SELECT job_job_type_map.job_id jobId, job_job_type_map.job_type_id jobTypeId,
job.title jobTitle, jobType.name jobTypeName
FROM job job, job_type jobType, job_job_type_map job_job_type_map
WHERE job_job_type_map.job_id = job.id
AND job_job_type_map.job_type_id = jobType.id
ORDER BY ${params.column} ${params.order}
LIMIT :limit
OFFSET :offset
"""
List<GroovyRowResult> result = sql.rows(query, params)
result.each {
println "${it.jobId} ${it.jobTypeId} ${it.jobTitle} ${it.jobTypeName}"
}
render template: 'list', model: [jobRows:result]
}
in GSP
<g:each in="${jobRows}" var="job">
"${job.jobId} ${job.jobTypeId} ${job.jobTitle} ${job.jobTypeName}" <br/>
</g:each>
Be careful ORDER BY ${params.column} ${params.order}
There is restriction in using named parameter in some places. You can find here
Enjoy!
If you do not want to change domain structure and do not want to write SQL/HSQL then you can use this approach:
def jobTypeId = JobType.findByName(params.jobTypeName).id
def jobIdList = JobJobTypeMap.findAllByJobTypeId(jobTypeId)?.jobId
def jobList = Job.createCriteria().list(max:max, offset:offset) {
'in'("id", jobIdList)
order("publishedDate", "desc")
}
jobList will give you the list of all jobs with specific job type, max, offset and order by publishedDate.
I'm using Github's API to fetch a user using https://api.github.com/user giving me something like this:
{
"login": "someuser123",
"id": 1234567,
"avatar_url": "https://avatars.githubusercontent.com/u/...",
...
}
but what is the data type for the id field? I can't seem to find any info on this in the API guides.
Found a bit of C# in the Octokit.net codebase that seems to indicate that User id is a 32-bit integer. From the User constructor (id is buried in the middle of the parameter list):
public User(string avatarUrl, string bio, string blog, int collaborators, string company, DateTimeOffset createdAt, int diskUsage, string email, int followers, int following, bool? hireable, string htmlUrl, int totalPrivateRepos, int id, string location, string login, string name, int ownedPrivateRepos, Plan plan, int privateGists, int publicGists, int publicRepos, string url, bool siteAdmin)
JSON has a limited set of data types, see https://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_example.
As the id is not null, true or false and not in quotes, it is a number. I won't expect decimal points, so it's something like an integer.