I am creating a connector that needs to upload documents to alfresco(in java), but the problem is that it cannot inject the service correctly. i am trying to do it like this:
"
@Component
@OutboundConnector(
name = “UploadToAlfresco”, inputVariables = {“files”, “filesNames”, “idProceso”}, type = “io.camunda:upload-document:1”)
public class Base64Function implements OutboundConnectorFunction {
private ICmisService cmisService;
@Autowired
public Base64Function(CmisService cmisService ) {
super();
this.cmisService = cmisService;
}
private static final Logger LOGGER = LoggerFactory.getLogger(Base64Function.class);
@Override
public Object execute(OutboundConnectorContext context) throws Exception {
var connectorRequest = context.getVariablesAsType(Base64Request.class);
context.replaceSecrets(connectorRequest);
return executeConnector(connectorRequest);
}
private Base64Result executeConnector(final Base64Request connectorRequest) throws IOException {
LOGGER.info("Executing my connector alfresco with request");
LOGGER.info("String: {}",connectorRequest.toString());
String[] filesNames= connectorRequest.getFilesNames();
byte[][] files= connectorRequest.getFiles();
Long idProceso= connectorRequest.getIdProceso();
List<MultipartFile> multipartFiles = convertBytesToMultipartFiles(files, filesNames);
if (null != multipartFiles && multipartFiles.size() > 0) {
for (MultipartFile multipartFile : multipartFiles) {
String fileName = multipartFile.getOriginalFilename();
try {
Document docCreated=cmisService.uploadDocumentToAlfresco( fileName, multipartFile, idProceso );
} catch (Exception e) {
e.printStackTrace();
}
}
}"
and it gives me this error:
org.springframework.context.ApplicationContextException: Failed to start bean ‘zeebeClientLifecycle’; nested exception is java.lang.IllegalStateException: Failed to load io.camunda.connector.Base64Function
I have also tried to do it like this:
“@Autowired
private ICmisService cmisService;”
but it gives me this error:
"java.lang.NullPointerException: Cannot invoke “io.camunda.interfaces.ICmisService.uploadDocumentToAlfresco(String, org.springframework.web.multipart.MultipartFile, java.lang.Long)” because “this.cmisService” is null
connectors | 2023-10-31 14:55:16.709 INFO 1 — [pool-4-thread-1] org.camunda.feel.FeelEngine : Engine created. [value-mapper: CompositeValueMapper(List(org.camunda.feel.impl.JavaValueMapper@1914d43)), function-provider: "
This is mi cmisservice class:
"@Service(“cmisService”)
public class CmisService implements ICmisService{
private static final Logger LOGGER = LoggerFactory.getLogger(CmisService.class);
@PostConstruct
public void init()
{
String alfrescoBrowserUrl = System.getenv("alfresco.repository.url") + "/api/-default-/public/cmis/versions/1.1/browser";
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.USER, "admin");
parameter.put(SessionParameter.PASSWORD, "admin");
parameter.put(SessionParameter.BROWSER_URL, "http://alfresco:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
SessionFactory factory = SessionFactoryImpl.newInstance();
session = factory.getRepositories(parameter).get(0).createSession();
}
//clases del cmis
public void updateProperties(CmisObject cmisObject, Map<String, Object> properties)
{
cmisObject.updateProperties(properties);
}
public ObjectId createRelationship(CmisObject sourceObject, CmisObject targetObject, String relationshipName)
{
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "a new relationship");
properties.put(PropertyIds.OBJECT_TYPE_ID, relationshipName);
properties.put(PropertyIds.SOURCE_ID, sourceObject.getId());
properties.put(PropertyIds.TARGET_ID, targetObject.getId());
return session.createRelationship(properties);
}
public void addAspect(CmisObject cmisObject, String aspect)
{
List<Object> aspects = cmisObject.getProperty("cmis:secondaryObjectTypeIds").getValues();
if (!aspects.contains(aspect))
{
aspects.add(aspect);
Map<String, Object> aspectListProps = new HashMap<String, Object>();
aspectListProps.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, aspects);
cmisObject.updateProperties(aspectListProps);
}
}
public ItemIterable<Relationship> getRelationships(ObjectId objectId, String relationshipName)
{
ObjectType typeDefinition = session.getTypeDefinition(relationshipName);
OperationContext operationContext = session.createOperationContext();
return session.getRelationships(objectId, true, RelationshipDirection.EITHER, typeDefinition, operationContext);
}
public void remove(CmisObject object)
{
if (BaseTypeId.CMIS_FOLDER.equals(object.getBaseTypeId()))
{
Folder folder = (Folder) object;
ItemIterable<CmisObject> children = folder.getChildren();
for (CmisObject child : children)
{
remove(child);
}
}
session.delete(object);
}
@Override
public Folder getDocLibFolder( String siteName, String folder) {
String path = "/Sites/" + siteName + "/documentLibrary" + folder;
return (Folder) session.getObjectByPath(path);
}"
So the problem is that my connector is not being able to access the cmis service.
How could i solve this?