PubServer API Documentation
Introduction
The PubServerAPI (com.priint.pubserverapi) was created to enable users and external systems to integrate with the publication management system. It provides a set of methods for managing documents, publications, page templates, users, notes, and other system components.
In addition to managing entities like documents and publications, the PubServer API also provides access to cache operations via PriintCacheServiceLocal. This allows developers to programmatically create, retrieve, and clear caches using the PriintCacheManager interface.
1. General API Usage Principles
To effectively navigate and understand the PubServer API, keep in mind the following common patterns that apply across most service interfaces:
- Retrieving by ID: Nearly all services provide methods to fetch a single object using its ID (e.g.,
getDocumentById,getPublicationById). These return anOptional<T>containing the object if it exists. - Querying collections: Most interfaces include a method to create a query builder (e.g.,
createDocumentQuery,createPublicationQuery) that lets you retrieve filtered lists of entities. Fluent API pattern is used for chaining query conditions. - Creating new objects: Methods that create resources (like documents or publications) typically return an ID of the newly created entity (e.g.,
DocumentId,PublicationId). - Updating, assigning, or deleting: Operations that modify state without returning data (like
update,assignToRoles,deleteById) usually have avoidreturn type. - **Service-specific exceptions: Each service typically defines its own subclass of PubServerBaseException for error handling (for example, UserServiceException, DocumentServiceException). Since PubServerBaseException extends RuntimeException, these are unchecked exceptions; you do not need to declare them in a method signature, but you should still handle them appropriately when calling methods that create, update, or retrieve resources.
- Domain-specific classes: Types such as Document, User, etc. are introduced in this API to represent key entities in the publication management system.
These patterns help maintain a consistent and predictable developer experience when working with different services in the API.
2. Example: Working with DocumentServiceLocal
This section provides practical examples to help you get started with using the PubServer API. You'll learn how to retrieve services, perform queries, and execute common operations like fetching, updating, and creating documents.
2.1 Getting a Service Interface
To interact with the API, first obtain a reference to the service you want to use. This is typically done using the PlannerEngineServiceLocator.
The PlannerEngineServiceLocator provides access to the various service interfaces. For instance, to work with documents:
DocumentServiceLocal documentServiceLocal = PlannerEngineServiceLocator.INSTANCE.getDocumentServiceLocal();
This example demonstrates accessing the DocumentServiceLocal, but the same pattern applies to other services such as PublicationServiceLocal, NoteServiceLocal, or UserServiceLocal, which can be retrieved using their corresponding get...() methods from PlannerEngineServiceLocator.INSTANCE.
2.2 Querying Documents by Criteria
Once you have a service reference, you can create queries to retrieve data based on specific conditions.
Most services provide a way to create a query object. For documents:
List<Document> documents = documentServiceLocal
.createDocumentQuery()
.labelLike("test")
.documentStage(DocumentStage.Preparation)
.documentType(DocumentType.STATIC)
.list();
This example filters documents whose label contains "Test", are in the Preparation stage, and are of type STATIC.
2.3. Retrieving a Single Document by ID
Sometimes you already know the document’s ID:
Optional<Document> documentById = documentServiceLocal.getDocumentById(DocumentId.of("documentId"));
Document document = documentById.orElseGet(() -> {
throw new ServiceRuntimeException("Document not found");
});
2.4 Updating an Existing Document
After retrieving a document, you can modify its properties and persist the changes using the update() method.
Once you retrieve a document, you can update its fields:
document.setDocumentTemplateId(DocumentId.of("documentId"));
document.setDocumentStage(DocumentStage.ContentAssignment);
documentServiceLocal.update(document);
2.5. Creating a Document from a Template
The API also supports creating new documents based on existing templates. This is useful when you want to generate predefined layouts or structures.
Beyond basic CRUD, some services—like DocumentServiceLocal