Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bandana Configuration could not be loaded because class could not be found

Parag Ashok Rathod January 9, 2017

I am new to Confluence , i am developing a Plugin that has ConfigurationManager class that will load and save List of Object which i will be using further to get data , but every time confluence got restart i am not able to load the List of Object data ,Please find below error 

[confluence.setup.bandana.ConfluenceDaoBandanaPersister] getObjectFromValue Configuration could not be loaded because class could not be found (context: _GLOBAL, key: com.cgi.exportcgiplugin.cgifiletemplates).

com.thoughtworks.xstream.converters.ConversionException: com.cgi.exportplugin.models.FileTemplateDetail : com.cgi.exportplugin.models.FileTemplateDetail
---- Debugging information ----
path : /list/com.cgi.exportplugin.models.FileTemplateDetail
message : com.cgi.exportplugin.models.FileTemplateDetail : com.cgi.exportplugin.models.FileTemplateDetail
required-type : java.util.List
line number : 2
cause-message : com.cgi.exportplugin.models.FileTemplateDetail : com.cgi.exportplugin.models.FileTemplateDetail
class : java.util.List
cause-exception : com.thoughtworks.xstream.alias.CannotResolveClassException
-------------------------------
com.thoughtworks.xstream.converters.ConversionException: com.cgi.exportplugin.models.FileTemplateDetail : com.cgi.exportplugin.models.FileTemplateDetail
---- Debugging information ----
path : /list/com.cgi.exportplugin.models.FileTemplateDetail
message : com.cgi.exportplugin.models.FileTemplateDetail : com.cgi.exportplugin.models.FileTemplateDetail
required-type : java.util.List
line number : 2
cause-message : com.cgi.exportplugin.models.FileTemplateDetail : com.cgi.exportplugin.models.FileTemplateDetail
class : java.util.List
cause-exception : com.thoughtworks.xstream.alias.CannotResolveClassException
-------------------------------
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:45)

 

Below is ConfigurationManager Class:


import com.atlassian.bandana.BandanaManager;
import com.atlassian.confluence.setup.bandana.ConfluenceBandanaContext;
import com.atlassian.spring.container.ContainerManager;
import com.cgi.exportplugin.models.FileTemplateDetail;
import java.util.*;
import com.thoughtworks.xstream.XStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public final class ConfigurationManager
{
/**
* The configuration object which holds the configuration of this plugin.
*/
private static final Logger log = LoggerFactory.getLogger(ConfigurationManager.class);

/**
* The bandana key for the configuration of this plugin.
*/
private static final String KEY_PREFIX_LIST_KEY = "com.cgi.exportcgiplugin.cgifiletemplates";

/**
* The bandana context to access the configuration of this plugin.
*/
private static final ConfluenceBandanaContext GLOBAL_CONTEXT = ConfluenceBandanaContext.GLOBAL_CONTEXT;

/**
* The XStream object used for serialisation.
*/
private XStream xStream;
/**
* The bandana manager of this confluence instance,
* used for storing the settings of this plugin.
*/
private BandanaManager bandanaManager;

/**
* The configuration object which holds the configuration of this plugin.
*/
private List<FileTemplateDetail> fileTemplateList = null;

public ConfigurationManager()
{
ContainerManager.autowireComponent(this);
xStream = new XStream();
xStream.setClassLoader(FileTemplateDetail.class.getClassLoader());
xStream.alias("FileTemplateDetail", FileTemplateDetail.class);
xStream.addImplicitCollection(ConfigurationManager.class, "fileTemplateList");
loadConfig();
}

/**
* This method is automatically called by Confluence to pass the
* bandana manager of this confluence instance.
*
* @param bandanaManager The bandana manager of this confluence manager
*/
public void setBandanaManager(BandanaManager bandanaManager) {
this.bandanaManager = bandanaManager;
}

/**
* This method deserializes the configuration object using
* bandana.
*/
public void loadConfig() {
log.info("Loading configuration.");
try {
/* check that the bandana manager exists */
if (this.bandanaManager == null)
{
throw new Exception("No bandana manager set.");
}

/* get the serialised configuration object */
Object data = bandanaManager.getValue( GLOBAL_CONTEXT, KEY_PREFIX_LIST_KEY );
/* check cast and deserialise */
if (data instanceof String) {
try {
/* Workaround: have to create a new xStream before deserialising */
Object deserialisedData = xStream.fromXML((String)data);
if (deserialisedData instanceof List<?>) {
this.fileTemplateList = (List) deserialisedData;
}
} catch (Exception e) {
this.log.error("Could not deserialise configuration.", e);
/* force the creation of a dummy configuration */
this.fileTemplateList = null;
}
}
/* check if we could load the configuration */
if (this.fileTemplateList == null) {
/* initialise a default configuration */
this.fileTemplateList = new ArrayList();
}
System.out.println("File Template Size in LoadConfig --> "+this.fileTemplateList.size());

} catch (Exception e) {
this.log.error("Could not load configuration.", e);
}
}
/*
Below Mathod for Listing All Templates
*/
public List<FileTemplateDetail> listAllTemplate() {
log.info("Inside ConfigurationManager.listAllTemplate() Method");
if(this.fileTemplateList == null){
loadConfig();
}
System.out.println("Size " + this.fileTemplateList.size());
return this.fileTemplateList;
}

public FileTemplateDetail getFileTemplate(String keyValue) {
log.info("Inside ConfigurationManager.getFileTemplate(String keyValue) Method");
if(this.fileTemplateList == null){
loadConfig();
}
FileTemplateDetail fileTemplateDetail = new FileTemplateDetail();
for (FileTemplateDetail fileTemplate : this.fileTemplateList) {
if (fileTemplate.getFileId().equals(keyValue)) {
fileTemplateDetail = fileTemplate;
break;
}
}
return fileTemplateDetail;
}

public void saveFileTemplateDetail(FileTemplateDetail fileTemplate) {
log.info("Inside ConfigurationManager.saveFileTemplateDetail(FileTemplateDetail fileTemplate) Method");
if(this.fileTemplateList == null){
loadConfig();
}
this.fileTemplateList.add(fileTemplate);
/* Workaround: have to create a new xstream before serialising */
xStream = new XStream();
xStream.setClassLoader(FileTemplateDetail.class.getClassLoader());
this.bandanaManager.setValue(GLOBAL_CONTEXT, KEY_PREFIX_LIST_KEY, xStream.toXML(this.fileTemplateList) );
}

public void deleteFileTemplateDetail(String keyValue) {
log.info("Inside ConfigurationManager.deleteFileTemplateDetail(String keyValue) Method");
if(this.fileTemplateList == null){
loadConfig();
}
for (FileTemplateDetail fileTemplate : this.fileTemplateList) {
if (fileTemplate.getFileId().equals(keyValue)) {
this.fileTemplateList.remove(fileTemplate);
break;
}
}
//xStream.toXML(
this.bandanaManager.setValue(GLOBAL_CONTEXT, KEY_PREFIX_LIST_KEY, this.fileTemplateList);
}

public void deleteAllTemplate() {
log.info("Inside ConfigurationManager.deleteAllTemplate() Method");
this.bandanaManager.setValue(GLOBAL_CONTEXT, KEY_PREFIX_LIST_KEY, new ArrayList());
}
}

 

Below is FileTemplateDetail Class

package com.cgi.exportplugin.models;

import javax.xml.bind.annotation.XmlElement;

//@javax.xml.bind.annotation.XmlRootElement(name = "FileTemplateDetail")
//@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
public class FileTemplateDetail
{
@XmlElement
private String fileId;
@XmlElement
private String filePath;
@XmlElement
private String fileName;
@XmlElement
private String fileDescription;
@XmlElement
private String fileVersion;
@XmlElement
private String fileType;
@XmlElement
private String lastAdded;
@XmlElement
private String lastedAddedOn;



public String getFileType()
{
return this.fileType;
}

public void setFileType(String fileType) {
this.fileType = fileType;
}

public String getLastAdded() {
return this.lastAdded;
}

public void setLastAdded(String lastAdded) {
this.lastAdded = lastAdded;
}

public String getLastedAddedOn() {
return this.lastedAddedOn;
}

public void setLastedAddedOn(String lastedAddedOn) {
this.lastedAddedOn = lastedAddedOn;
}

public String getFileId() {
return this.fileId;
}

public void setFileId(String fileId) { this.fileId = fileId; }

public String getFilePath() {
return this.filePath;
}

public void setFilePath(String filePath) { this.filePath = filePath; }

public String getFileName() {
return this.fileName;
}

public void setFileName(String fileName) { this.fileName = fileName; }

public String getFileDescription() {
return this.fileDescription;
}

public void setFileDescription(String fileDescription) { this.fileDescription = fileDescription; }

public String getFileVersion() {
return this.fileVersion;
}

public void setFileVersion(String fileVersion) { this.fileVersion = fileVersion; }
}

 


 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2017

I recommend to use Active Objects instead of the Bandana. Please check comments here: https://answers.atlassian.com/questions/45972183 taking into account that Bandana is similar top PluginSettings.

If you really want to proceed the Bandana way: Looks like deserialization code does not see the FileTemplateDetail (I assume that's your class). You should be able to fix this by launching your code after the plugin is fully loaded. Please check the initialization code here: https://bitbucket.org/cfuller/atlassian-scheduler-jira-example/src/371cbc419c5a4fa3197d4dc28ddeb21105718a43/src/main/java/com/atlassian/jira/plugins/example/scheduler/impl/AwesomeLauncher.java?at=master&fileviewer=file-view-default. Study the comment and probably the best approach is just to copy all the flow that precedes call of the "launch" method.

TAGS
AUG Leaders

Atlassian Community Events