Hi.
I am trying to add an array of AdminTag using the AdminTagMgr. I am extending BaseApiExample.java
List < AdminTag > adminTags = new ArrayList < > ();
lookupConsumer.getChildren().forEach(child - > {
System.out.println(child.getName());
AdminTag adminTag = new AdminTag();
adminTag.setName(child.getName());
adminTag.setLanguageId(AdminLanguageMgr.DEFAULT_LANG);
adminTag.setTagGroups(new AdminTagGroup[] {adminTagGroup});
adminTags.add(adminTag);
});
try {
AdminTag[] arr = adminTags.toArray(new AdminTag[adminTags.size()]);
adminTagMgr.insertTags(sessionId, arr);
} catch (Exception e) {
System.out.println(String.format("Unable to add tags: %s", e));
}
When I run this, only the first tag is saved, even though they have completely differnt names. Adding tags with the same name in the admin application is no problem so I do not understand why this is failing.
I have removed all languages but the default English.
com.konakartadmin.app.KKAdminException: Exception Message = (org.apache.torque.TorqueException) - org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "kk_tag_pkey"
Detail: Key (tag_id, language_id)=(4, 1) already exists.
Do I need to fill out the ID of the AdminTag my self ? Shouldn't the AdminTag's ID be created automatically on insert ?
/**
* Insert an array of Tag objects - provide a Tag record for each supported language.
*
* @param sessionId
* session Id of logged in Admin user
* @param tags
* the array of AdminTag objects to insert - do not fill out the Id on these (set
* them to -1) as this will be created. It is assumed that all of these tags will
* have the same ID, and there will be one for each language.
* @return the id of the AdminTag object created
* @throws KKAdminException
*/
public int insertTags(String sessionId, AdminTag[] tags) throws KKAdminException;
The API call is intended for tags with the same id but different languages. If you only have one language then you can use :
/**
* Insert a new Tag object
*
* @param sessionId
* session Id of logged in Admin user
* @param tag
* the new AdminTag object to insert - do not fill out the Id (set it to -1) as this
* will be created
* @return the id of the AdminTag object created
* @throws KKAdminException
*/
public int insertTag(String sessionId, AdminTag tag) throws KKAdminException;
The documentation for com.konakartadmin.bl.AdminTagMgr.insertTag is a little bit off in the JavaDoc. KonaKart 8.0.0.0
It states there that the Id should not be filled out.
Quote
insertTag
public int insertTag(java.lang.String sessionId, AdminTag tag) throws java.lang.Exception
Insert a new Tag object. If associated TagGroups are included in the tag object (i.e. not null and at least one of them) these are also added to the kk_tag_group_to_tag table.
Specified by:
insertTag in interface AdminTagMgrIf
Parameters:
sessionId - session Id of logged in Admin user
tag - the new AdminTag object to insert - do not fill out the Id (unless inserting a tag for a new language) as this will be created. If the tag specifies -1 (KonakartAdminConstants.DEFAULT_LANGUAGE_ID) for the languageId, we set the id of the default language before inserting)
Returns:
the id of the AdminTag object created
Throws: java.lang.Exception
However in your JavaDoc, it says "
do not fill out the Id (set it to -1) as this will be created". Setting the id as -1 looks awfully lot like filling out the id variable.
Shouldn't the id variable in AdminTag be set to -1 in the constructor by default if the default behavior should be to create a new id ?