public class

DrupalConnector

extends Object
java.lang.Object
   ↳ org.mule.modules.drupal.DrupalConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Drupal is an open source content management platform powering millions of websites and applications. This connector allow you to integrate with a drupal server running the rest server.

Summary

Fields
private String apiUrl Path to the REST api
protected DrupalClient client Instance of a DrupalRestClient
private String commentEndpoint Path relative to the REST api url for the Comment Resource.
private String fileEndpoint Path relative to the REST api url for the File Resource.
private String nodeEndpoint Path relative to the REST api url for the Node Resource.
private int port Port of the connecion
private String server Uri of the server
private String taxonomyTermEndpoint Path relative to the REST api url for the TaxonomyTerm Resource.
private String taxonomyVocabularyEndpoint Path relative to the REST api url for the TaxonomyVocabulary Resource.
private String userEndpoint Path relative to the REST api url for the User Resource.
Public Constructors
DrupalConnector()
Public Methods
void connect(String username, String password)
Connect
String connectionId()
Are we connected
int countAllComments(int nodeId)
Count all comments in a node

int countNewComments(int nodeId, int since)
Counts all new comments in a node.
Comment createComment(Comment comment)
Create a comment.
File createFile(File file)
Create a file

Node createNode(Node node)
Creates a node.
TaxonomyTerm createTaxonomyTerm(TaxonomyTerm taxonomyTerm)
Create a taxonomy term

TaxonomyVocabulary createTaxonomyVocabulary(TaxonomyVocabulary taxonomyVocabulary)
Create a taxonomyVocabulary

User createUser(User user)
Create a User

void deleteComment(int commentId)
Delete a comment

void deleteFile(int fileId)
Delete a file.
void deleteNode(int nodeId)
Delete a node

void deleteTaxonomyTerm(int taxonomyTermId)
Delete a Term

void deleteTaxonomyVocabulary(int taxonomyVocId)
Delete a Vocabulary

void deleteUser(int userId)
Delete an User

void disconnect()
Disconnect
String getApiUrl()
String getCommentEndpoint()
List<Comment> getCommentsForNode(int nodeId)
Get the list of comments of a node

String getFileEndpoint()
List<File> getFilesForNode(int nodeId)
Get the list of files attached of a node

String getNodeEndpoint()
List<Node> getNodesWithTerm(int taxonomyTermId)
Get a list of Nodes related to the term

int getPort()
String getServer()
String getTaxonomyTermEndpoint()
String getTaxonomyVocabularyEndpoint()
List<TaxonomyTerm> getTaxonomyVocabularyTree(int vocabularyId, int parent, int maxdepth)
The the list of terms that match the requirements of the request.
String getUserEndpoint()
List<Comment> indexComments(List<String> fields, int startPage, int pagesize)
Get a list of Comments with only the fields specified in the list of fields and the uri field for the comment.
List<File> indexFiles(List<String> fields, int startPage, int pagesize)
Get a list of files with only the fields specified in the list of fields and the uri field for the File.
List<Node> indexNodes(List<String> fields, int startPage, int pagesize)
Get a list of Nodes with only the fields specified in the list of fields and the uri field for the node.
List<TaxonomyTerm> indexTaxonomyTerms(List<String> fields, int startPage, int pagesize)
Get a list of taxonomy terms with only the fields specified in the list of fields and the uri field for the term.
List<TaxonomyVocabulary> indexTaxonomyVocabulary(List<String> fields, int startPage, int pagesize)
Get a list of taxonomy vocabulary with only the fields specified in the list of fields and the uri field for the vocabulary.
List<User> indexUsers(List<String> fields, int startPage, int pagesize)
Get a list of Users with only the fields specified in the list of fields and the uri field for the user.
boolean isConnected()
Are we connected
Comment readComment(String commentId)
Read a comment.
File readFile(String fileId)
Read a file.
Node readNode(String nodeId)
Read a node.
TaxonomyTerm readTaxonomyTerm(String taxonomyTermId)
Read a taxonomy term.
TaxonomyVocabulary readTaxonomyVocabulary(String vocabularyId)
Read a taxonomy vocabulary.
User readUser(String userId)
Read an user.
User registerUser(User user)
Register a user

void setApiUrl(String apiUrl)
void setCommentEndpoint(String commentEndpoint)
void setFileEndpoint(String fileEndpoint)
void setNodeEndpoint(String nodeEndpoint)
void setPort(int port)
void setServer(String server)
void setTaxonomyTermEndpoint(String taxonomyTermEndpoint)
void setTaxonomyVocabularyEndpoint(String taxonomyVocabularyEndpoint)
void setUserEndpoint(String userEndpoint)
Comment updateComment(Comment comment)
Update the comment

void updateCustomFieldForNode(int nodeId, String fieldName, Map<String, String> customProperties)
Update one custom field with the properties set at the map

File updateFile(File file)
Update file

Node updateNode(Node node)
Update the node

TaxonomyTerm updateTaxonomyTerm(TaxonomyTerm taxonomyTerm)
Update the taxonomy term

TaxonomyVocabulary updateTaxonomyVocabulary(TaxonomyVocabulary taxonomyVocabulary)
Update the taxonomyVocabulary

User updateUser(User user)
Update the user

[Expand]
Inherited Methods
From class java.lang.Object

Fields

private String apiUrl

Path to the REST api

protected DrupalClient client

Instance of a DrupalRestClient

private String commentEndpoint

Path relative to the REST api url for the Comment Resource.

private String fileEndpoint

Path relative to the REST api url for the File Resource.

private String nodeEndpoint

Path relative to the REST api url for the Node Resource.

private int port

Port of the connecion

private String server

Uri of the server

private String taxonomyTermEndpoint

Path relative to the REST api url for the TaxonomyTerm Resource.

private String taxonomyVocabularyEndpoint

Path relative to the REST api url for the TaxonomyVocabulary Resource.

private String userEndpoint

Path relative to the REST api url for the User Resource.

Public Constructors

public DrupalConnector ()

Public Methods

public void connect (String username, String password)

Connect

Parameters
username A username
password A password
Throws
ConnectionException

public String connectionId ()

Are we connected

public int countAllComments (int nodeId)

Count all comments in a node

Parameters
nodeId Node Id
Returns
  • Amount of comments on the given node
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public int countNewComments (int nodeId, int since)

Counts all new comments in a node.

Parameters
nodeId Node Id
since Unix like date format. Default value is 0.
Returns
  • Amount of new comments
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public Comment createComment (Comment comment)

Create a comment.

The comment needs to have the node id set. If the comment is related to another comment in the same node, you need to specify the comment id by setting the pid. See Comment.

Parameters
comment Comment with a subject, body and node id
Returns
  • The comment with the Id set by the server
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public File createFile (File file)

Create a file

Parameters
file File that has the content encoded in Base64 and the name of the file.
Returns
  • the file with the Id set.
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public Node createNode (Node node)

Creates a node.

Parameters
node Node. The minimum required fields that need to be set are the Type and Title. See Node
Returns
  • The node with the Id set by the server
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public TaxonomyTerm createTaxonomyTerm (TaxonomyTerm taxonomyTerm)

Create a taxonomy term

Parameters
taxonomyTerm TaxonomyTerm
Returns
  • the same TaxonomyTerm created
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public TaxonomyVocabulary createTaxonomyVocabulary (TaxonomyVocabulary taxonomyVocabulary)

Create a taxonomyVocabulary

Parameters
taxonomyVocabulary TaxonomyVocabulary
Returns
  • the TaxonomyVocabulary.
Throws
DrupalException When the server doesn't return code 200, it contains the code returned. Error 500 is thrown when the vocabulary already exists

public User createUser (User user)

Create a User

Parameters
user User with at least Name, mail and password set.
Returns
  • The user with the Id set by the server
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void deleteComment (int commentId)

Delete a comment

Parameters
commentId Id of the comment
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void deleteFile (int fileId)

Delete a file. If the file is associated to any content, then it can not be deleted.

Parameters
fileId Id of the file
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void deleteNode (int nodeId)

Delete a node

Parameters
nodeId Id of the node
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void deleteTaxonomyTerm (int taxonomyTermId)

Delete a Term

Parameters
taxonomyTermId Id of the term
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void deleteTaxonomyVocabulary (int taxonomyVocId)

Delete a Vocabulary

Parameters
taxonomyVocId Id of the vocabulary
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void deleteUser (int userId)

Delete an User

Parameters
userId Id of the User
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void disconnect ()

Disconnect

public String getApiUrl ()

public String getCommentEndpoint ()

public List<Comment> getCommentsForNode (int nodeId)

Get the list of comments of a node

Parameters
nodeId The id of the node
Returns
  • List of Comment
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public String getFileEndpoint ()

public List<File> getFilesForNode (int nodeId)

Get the list of files attached of a node

Parameters
nodeId The node Id
Returns
  • List of Files
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public String getNodeEndpoint ()

public List<Node> getNodesWithTerm (int taxonomyTermId)

Get a list of Nodes related to the term

Parameters
taxonomyTermId The term id of the tag we want the nodes to be associated with
Returns
  • List of nodes that have the term.
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public int getPort ()

public String getServer ()

public String getTaxonomyTermEndpoint ()

public String getTaxonomyVocabularyEndpoint ()

public List<TaxonomyTerm> getTaxonomyVocabularyTree (int vocabularyId, int parent, int maxdepth)

The the list of terms that match the requirements of the request.

Parameters
vocabularyId Id of the TaxonomyVocabulary we want to get
parent The TaxonomyTerm id we will use to filter the results. Defatuls to -1. In this case the parameter willl be ignored
maxdepth Max depth value of the terms tree we want to retrieve. It is an exclusive limit. Only terms with lower depth value will be retrieved. Default value is 0. In this case parameter will be ignored
Returns
  • A list of terms. The tree is actually the relationship that exists between the TaxonomyTerm parent field and the tid field. See TaxonomyTerm
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public String getUserEndpoint ()

public List<Comment> indexComments (List<String> fields, int startPage, int pagesize)

Get a list of Comments with only the fields specified in the list of fields and the uri field for the comment.

Parameters
fields List of fields of the comment that we want to retrieve. See Comment
startPage The start page of the result list. Default value is -1. In this case, parameter won't be used in the request
pagesize The maximum amount of results per page. Default value is 0.In this case, parameter won't be used in the request
Returns
  • List of comments with the required fields and the uri
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public List<File> indexFiles (List<String> fields, int startPage, int pagesize)

Get a list of files with only the fields specified in the list of fields and the uri field for the File.

Parameters
fields List of fields of the File that we want to retrieve. See File
startPage The start page of the result list. Default value is -1. In this case, parameter won't be used in the request
pagesize The maximum amount of results per page. Default value is 0.In this case, parameter won't be used in the request
Returns
  • List of files with the required fields and the uri
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public List<Node> indexNodes (List<String> fields, int startPage, int pagesize)

Get a list of Nodes with only the fields specified in the list of fields and the uri field for the node.

Parameters
fields List of fields of the node that we want to retrieve.See Node
startPage The start page of the result list. Default value is -1. In this case, parameter won't be used in the request
pagesize The maximum amount of results per page. Default value is 0.In this case, parameter won't be used in the request
Returns
  • List of nodes with the required fields and the uri
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public List<TaxonomyTerm> indexTaxonomyTerms (List<String> fields, int startPage, int pagesize)

Get a list of taxonomy terms with only the fields specified in the list of fields and the uri field for the term.

Parameters
fields List of fields of the TaxonomyTerm that we want to retrieve. See TaxonomyTerm
startPage The start page of the result list. Default value is -1. In this case, parameter won't be used in the request
pagesize The maximum amount of results per page. Default value is 0.In this case, parameter won't be used in the request
Returns
  • List of terms with the required fields and the uri
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public List<TaxonomyVocabulary> indexTaxonomyVocabulary (List<String> fields, int startPage, int pagesize)

Get a list of taxonomy vocabulary with only the fields specified in the list of fields and the uri field for the vocabulary.

Parameters
fields List of fields of the TaxonomyVocabulary that we want to retrieve. See TaxonomyVocabulary
startPage The start page of the result list. Default value is -1. In this case, parameter won't be used in the request
pagesize The maximum amount of results per page. Default value is 0.In this case, parameter won't be used in the request
Returns
  • List of vocabularies with the required fields and the uri
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public List<User> indexUsers (List<String> fields, int startPage, int pagesize)

Get a list of Users with only the fields specified in the list of fields and the uri field for the user.

Parameters
fields List of fields of the user that we want to retrieve. See User
startPage The start page of the result list. Default value is -1. In this case, parameter won't be used in the request
pagesize The maximum amount of results per page. Default value is 0.In this case, parameter won't be used in the request
Returns
  • List of users with the required fields and the uri
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public boolean isConnected ()

Are we connected

public Comment readComment (String commentId)

Read a comment. See Comment

Parameters
commentId Number of comment
Returns
  • Comment with the id specified
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public File readFile (String fileId)

Read a file. See File

Parameters
fileId Number of file
Returns
  • File with the id specified
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public Node readNode (String nodeId)

Read a node. See Node.

Parameters
nodeId Number of node
Returns
  • Node with the id specified
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public TaxonomyTerm readTaxonomyTerm (String taxonomyTermId)

Read a taxonomy term. See TaxonomyTerm

Parameters
taxonomyTermId Number of the term
Returns
  • Taxonomy term with the id specified
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public TaxonomyVocabulary readTaxonomyVocabulary (String vocabularyId)

Read a taxonomy vocabulary.

Parameters
vocabularyId Number of the vocabulary
Returns
  • Taxonomy vocabulary with the id specified
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public User readUser (String userId)

Read an user. See User

Parameters
userId Number of user
Returns
  • User with the id specified
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public User registerUser (User user)

Register a user

Parameters
user User with at least Name, mail and password set.
Returns
  • The user created
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void setApiUrl (String apiUrl)

Parameters
apiUrl

public void setCommentEndpoint (String commentEndpoint)

Parameters
commentEndpoint

public void setFileEndpoint (String fileEndpoint)

Parameters
fileEndpoint

public void setNodeEndpoint (String nodeEndpoint)

Parameters
nodeEndpoint

public void setPort (int port)

Parameters
port

public void setServer (String server)

Parameters
server

public void setTaxonomyTermEndpoint (String taxonomyTermEndpoint)

Parameters
taxonomyTermEndpoint

public void setTaxonomyVocabularyEndpoint (String taxonomyVocabularyEndpoint)

Parameters
taxonomyVocabularyEndpoint

public void setUserEndpoint (String userEndpoint)

Parameters
userEndpoint

public Comment updateComment (Comment comment)

Update the comment

Parameters
comment Comment with new fields set
Returns
  • the same comment
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public void updateCustomFieldForNode (int nodeId, String fieldName, Map<String, String> customProperties)

Update one custom field with the properties set at the map

Parameters
nodeId Id of the node
fieldName Machine name of the field
customProperties Map that contains the pair of key and values
Throws
DrupalException When the server doesn't return code 200

public File updateFile (File file)

Update file

Parameters
file File with new fields set
Returns
  • the same File
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public Node updateNode (Node node)

Update the node

Parameters
node Node
Returns
  • the same node
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public TaxonomyTerm updateTaxonomyTerm (TaxonomyTerm taxonomyTerm)

Update the taxonomy term

Parameters
taxonomyTerm TaxonomyTerm with new fields set
Returns
  • the same taxonomyTerm
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public TaxonomyVocabulary updateTaxonomyVocabulary (TaxonomyVocabulary taxonomyVocabulary)

Update the taxonomyVocabulary

Parameters
taxonomyVocabulary Taxonomy vocabulary with new fields set
Returns
  • The same taxonomyVocabulary
Throws
DrupalException When the server doesn't return code 200, it contains the code returned

public User updateUser (User user)

Update the user

Parameters
user User with new fields set
Returns
  • the same user
Throws
DrupalException When the server doesn't return code 200, it contains the code returned