500 Error-Alternate to ComponentAccessor.getAttachmentPathManager().getAttachmentPath();

I have the following code.

private static File getAttachmentDirectory(final String projectKey, final Integer entityId, final String entityType, final boolean createDirectory)
    {
    	
        final File directory = getAttachmentDirectory(getAttachmentDirName(), projectKey, entityId,entityType);
        if (createDirectory)
        {
            //noinspection ResultOfMethodCallIgnored
            directory.mkdirs();
        }
        log.debug("Fetching attachment directory completed");
        return directory;
    }
public static String getAttachmentDirName()
    {
    	ClusterProperties clusterProperties = (ClusterProperties) ZephyrComponentAccessor.getInstance().getComponent("clusterProperties");
    	String shareHome = clusterProperties.getSharedHome();
    	String attachmentsDirectory = Paths.get(shareHome, "data", "attachments").toAbsolutePath().toString();
    	return attachmentsDirectory;
//    	return 
//        return ComponentAccessor.getAttachmentPathManager().getAttachmentPath();
    }

It seems in Jira 10, ComponentAccessor.getAttachmentPathManager().getAttachmentPath();
It has been removed/deprecated. Can anyone suggest anyother way or alternate way to get the path?
I commented the code and added the below lines
ClusterProperties clusterProperties = (ClusterProperties) ZephyrComponentAccessor.getInstance().getComponent("clusterProperties"); String shareHome = clusterProperties.getSharedHome(); String attachmentsDirectory = Paths.get(shareHome, "data", "attachments").toAbsolutePath().toString(); return attachmentsDirectory;

But still this is not working.
We are using Java 17, and I have mentioned the bean in application-context.xml

<constructor-arg index="10" type="com.thed.zephyr.je.index.cluster.ClusterProperties" ref="clusterProperties"/>

Can anyone suggest any other solution for this, specifically an alternate to
ComponentAccessor.getAttachmentPathManager().getAttachmentPath();

2 Likes

You can find all the relevant docs here, it was deprecated in Jira 9.7 :slight_smile:

Hey @PaoloCampanelli ,
I tried above solution that you provided but it’s not working.


Here it’s written alternative endpoint, but sln is not there.

atlassian-plugin.xml

<component key="clusterProperties" name="Cluster Properties"
               class="com.thed.zephyr.je.index.cluster.ClusterPropertiesImpl">
        <interface>com.thed.zephyr.je.index.cluster.ClusterProperties</interface>
    </component>
package com.thed.zephyr.je.index.cluster;

import java.io.File;

import javax.annotation.Nullable;

/**
 * This is used to lookup cluster properties from the underlying properties file.
 *
 */
public interface ClusterProperties
{
    /**
     *
     * @param key key for the property you want to look up
     * @return String value of the property, null if it does not exist
     */

    @Nullable
    String getProperty(String key);

    /**
     * Get the shared home for a clustered installation.
     * Will return null if no shared home is set.
     * @return
     */
    String getSharedHome();

    /**
     * Get the node id for a clustered installation.
     * Will return null if no node id is set.
     * @return
     */
    String getNodeId();
    
    /**
     * Gets the home directory for server.
     * @return {@link String}
     */
    String getHomeDirectory();
    
    File getLogDiretory();
}

public static String getAttachmentDirName()
    {
        Object component = ZephyrComponentAccessor.getInstance().getComponent("clusterProperties");
        if (!(component instanceof ClusterProperties)) {
            throw new IllegalStateException("ClusterProperties bean is not of the expected type");
        }
        ClusterProperties clusterProperties = (ClusterProperties) component;
//    	ClusterProperties clusterProperties = (ClusterProperties) ZephyrComponentAccessor.getInstance().getComponent("clusterProperties");
    	String shareHome = clusterProperties.getSharedHome();
    	String attachmentsDirectory = Paths.get(shareHome, "data", "attachments").toAbsolutePath().toString();
    	return attachmentsDirectory;}
package com.thed.zephyr.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.atlassian.activeobjects.external.ActiveObjects;

public class ZephyrComponentAccessor implements ApplicationContextAware{
	
	private static ZephyrComponentAccessor instance;
	
	private ApplicationContext applicationContext;

	private ActiveObjects activeObjects;
	
	
	public ZephyrComponentAccessor(ActiveObjects ao) {
		super();
		this.activeObjects = ao;
		instance = this;
	}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}
	
	public Object getComponent(String key){
		if(isSetup())
			return applicationContext.getBean(key);
		return null;
	}


	public static Boolean isSetup(){
		return instance != null;
	}

	public static ZephyrComponentAccessor getInstance() {
		return instance;
	}

	public ActiveObjects getActiveObjects() {
		return activeObjects;
	}
	
}

The function is going into throw exception block i.e. -“ClusterProperties bean is not of the expected type”

Please help, what else can I do.