Class PObject

java.lang.Object
com.polarion.platform.persistence.spi.PObject
All Implemented Interfaces:
IAdaptable, IChangeListener, IHasCustomValues, IHasValues, IPObject, IHasChangeListeners, Serializable
Direct Known Subclasses:
Revision

public class PObject extends Object implements IPObject, Serializable, IHasChangeListeners
The base implementation of IPObject interface. Because the backend implementation cooperates with this class, implementors of model-specific type interfaces must extend it.
Author:
dobisekm
See Also:
  • Constructor Details

    • PObject

      public PObject(@NotNull IDataService dataSvc, @NotNull IPrototype prototype)
      Creates an instance of new PObject, which is not yet persistent. Saving this object will cause call to the creation methods.
      Parameters:
      dataSvc -
      prototype -
    • PObject

      public PObject(@NotNull IDataService dataSvc, @NotNull SubterraURI uri)
      Creates unresolved PObject, actually the same as PObject(dataSvc, uri, null)
    • PObject

      public PObject(@NotNull IDataService dataSvc, @NotNull com.polarion.subterra.base.data.object.IDataObject dao)
      Creates resolved PObject, the same as PObject(dataSvc, dao.getId(), dao)
      Parameters:
      dataSvc -
      dao -
    • PObject

      public PObject(@NotNull IDataService dataSvc, @NotNull SubterraURI uri, @Nullable com.polarion.subterra.base.data.object.IDataObject dao)
      Creates the resolved PObject (if dao != null)
  • Method Details

    • setDao

      public final void setDao(@Nullable com.polarion.subterra.base.data.object.IDataObject dao)
      Used by backend to resolve the content of this PObject.

      Should not be called by ordinary clients.

      Parameters:
      dao -
    • setURI

      public final void setURI(@Nullable SubterraURI uri)
      Used by the backend during object creation, must not be called by clients.
      Parameters:
      uri -
    • getData

      @Nullable public final com.polarion.subterra.base.data.object.IDataObject getData()
      Returns low level data. Used by backend only. Client calls to this method can result in unpredictable behaviour.
    • isPersisted

      public boolean isPersisted()
      Specified by:
      isPersisted in interface IPObject
      Returns:
      false for temporary objects, true otherwise. Some operations are disallowed on temporary objects (since they don't have uri yet).
    • getPrototype

      public IPrototype getPrototype()
      Specified by:
      getPrototype in interface IPObject
    • getUri

      @NotNull public SubterraURI getUri()
      Specified by:
      getUri in interface IPObject
      Returns:
      The object's URI.
    • getObjectId

      public IObjectId getObjectId()
      Description copied from interface: IPObject
      Convenience method to extract the IObjectId from the object's SubterraURI.
      Specified by:
      getObjectId in interface IPObject
      Returns:
      the IObjectId assigned to this object
    • getLocalId

      public ILocalId getLocalId()
      Description copied from interface: IPObject
      Convenience method to get the local id
      Specified by:
      getLocalId in interface IPObject
    • getContextId

      public IContextId getContextId()
      Specified by:
      getContextId in interface IPObject
    • getRevision

      public String getRevision()
      Description copied from interface: IPObject
      Convenience method to extract the revision from the object's SubterraURI.
      Specified by:
      getRevision in interface IPObject
      Returns:
      The revision name or null if this object is not taken from any particular revision.
    • getDataRevision

      @Nullable public String getDataRevision()
      Description copied from interface: IPObject
      Returns revision from which the data was actualy read.
      Specified by:
      getDataRevision in interface IPObject
      Returns:
      the String representing the id associated with this objects data
    • getLastRevision

      @Nullable public String getLastRevision()
      Description copied from interface: IPObject
      Returns the last revision in the History of this object. (Does not return revisions from included child objects like Work Items or Document Workflow Signatures.)
      Specified by:
      getLastRevision in interface IPObject
    • getValue

      public Object getValue(String key)
      Specified by:
      getValue in interface IHasValues
      Specified by:
      getValue in interface IPObject
      Returns:
      The value of given key. This handles both the ordinary fields (as defined by prototype) and the custom fields. Returns null if the field has no value (or does not exist). Never returns null for collection fields defined by prototype (empty collection is returned instead).
    • getSecurityReferee

      public ISecurityReferee getSecurityReferee(String key)
      Return security referee for given key.

      Allows to redirect security checking of lists and structures to another object (especially useful for fields which are stored in one object, but are shown as if they were part of another object) when overridden.

      Parameters:
      key - key
      Returns:
      security referee or null (which allows everything)
    • setBypassInstanceModificationSecurityCheck

      public void setBypassInstanceModificationSecurityCheck(boolean bypass)
    • isBypassingInstanceModificationSecurityCheck

      public boolean isBypassingInstanceModificationSecurityCheck()
    • checkReadOnly

      public void checkReadOnly()
      Throws ReadOnlyException when isReadOnly() returns true.
      Since:
      3.23.10
    • setValue

      public void setValue(String key, Object value)
      Description copied from interface: IPObject
      Sets the value of given field. This works with both ordinary fields (as defined by prototype) and the custom fields. But the field correctness is checked, therefore it's not possible to set value of unknown custom field.
      Specified by:
      setValue in interface IHasValues
      Specified by:
      setValue in interface IPObject
      Parameters:
      key - Name of field defined by prototype or custom field, which is configured for this object OR already exists in this object.
    • getCustomField

      @Nullable public Object getCustomField(@NotNull String key)
      Specified by:
      getCustomField in interface IHasCustomValues
      Parameters:
      key - The value of the given custom field or null if no such value exists.
    • setCustomField

      public void setCustomField(@NotNull String key, @Nullable Object value)
      Description copied from interface: IHasCustomValues
      Sets the value of the given custom field. The value type must be checked against the custom field configuration. If the field configuration does not exist, only the String value is accepted.
      Specified by:
      setCustomField in interface IHasCustomValues
    • getCustomFieldsList

      @NotNull public Collection<String> getCustomFieldsList()
      Specified by:
      getCustomFieldsList in interface IHasCustomValues
      Returns:
      Collection of String names of custom fields, which are defined for this object or exist on this object.
    • getCustomFieldPrototype

      @NotNull public ICustomField getCustomFieldPrototype(@NotNull String key)
      Description copied from interface: IHasCustomValues
      Shortcut for ICustomFieldsService.getCustomField(key, getProtoName(), getContextId())
      Specified by:
      getCustomFieldPrototype in interface IHasCustomValues
      See Also:
    • getIncompatibleCustomField

      public Object getIncompatibleCustomField(String key)
      Specified by:
      getIncompatibleCustomField in interface IPObject
      Returns:
      value of incompatible custom field key
    • getIncompatibleCustomFieldPrototype

      @Nullable public ICustomField getIncompatibleCustomFieldPrototype(String key)
      Specified by:
      getIncompatibleCustomFieldPrototype in interface IPObject
      Returns:
      prototype of incompatible custom field key
    • getIncompatibleCustomFieldsList

      @NotNull public Set<String> getIncompatibleCustomFieldsList()
      Specified by:
      getIncompatibleCustomFieldsList in interface IPObject
      Returns:
      Set of names of custom fields which are persisted in this work item but not compatible with their current definition (i. e. persisted as a String but currently defined to be an Integer)
    • isReadOnly

      public boolean isReadOnly()
      Description copied from interface: IPObject
      All write attempts on read-only objects will end up with exception.

      Temporary objects are never read-only, even their fields, which are defined as read-only in prototype can be written to temporary objects (since they are likely needed during the creation).

      Specified by:
      isReadOnly in interface IPObject
      Returns:
      true is this object is read-only, false otherwise. There are several reasons for object to be read-only: it can be marked on prototype or recognized from the URL (which points to particular version of the object) or when the current transaction is read-only.
    • isModified

      public boolean isModified()
      Specified by:
      isModified in interface IPObject
      Returns:
      True is this object was modified since it's load, false otherwise.
    • createStructureForKey

      public IStructure createStructureForKey(String key)
      Description copied from interface: IPObject
      Creates the instance of structure object, which corresponds to model definition. Use the dot notation, if the structure is under another structure (e.g. mystructure.substructure) This is a shortcut method for IPObject.createStructureForKey(String).
      Specified by:
      createStructureForKey in interface IPObject
      Returns:
      the IStructure created for the specified key
    • markUnresolvable

      public void markUnresolvable(@Nullable RuntimeException cause)
    • addChangeListener

      public void addChangeListener(@NotNull IChangeListener listener)
      Internal API, do not use.
      Specified by:
      addChangeListener in interface IHasChangeListeners
      Since:
      3.19.3
    • isUnresolvable

      public boolean isUnresolvable()
      Description copied from interface: IPObject
      This method guarantees that the object is either resolved, or unresolvable.
      Specified by:
      isUnresolvable in interface IPObject
      Returns:
      false if this object is resolved. Returns true if attempt to resolve did fail. If this method returns true then all attempts to call get/set methods will result in exception.
    • isResolved

      public boolean isResolved()
      Specified by:
      isResolved in interface IPObject
      Returns:
      Returns true is data of this object are already loaded, false otherwise.
    • resolve

      public void resolve()
      Description copied from interface: IPObject
      Resolves the object content if not yet resolved. (reads it from the associated IDataService. In case the object is already resolved, calling this method does nothing.
      Specified by:
      resolve in interface IPObject
      See Also:
    • save

      public void save()
      Description copied from interface: IPObject
      Saves the content of this object into the associated IDataService.
      Specified by:
      save in interface IPObject
      See Also:
    • update

      public void update()
      Description copied from interface: IPObject
      Reloads the content of this object from the associated IDataService. This reverts any changes done to this object.

      This method is equivalent to IPObject.forget() followed by IPObject.resolve().

      Specified by:
      update in interface IPObject
      See Also:
    • forget

      public void forget()
      Description copied from interface: IPObject
      Forgets the content of this object. The underlying data are disposed, just the SubterraURI remains. This disposes any changes made to this object (if not saved before).
      Specified by:
      forget in interface IPObject
    • markChanged

      public void markChanged()
      Specified by:
      markChanged in interface IChangeListener
    • exists

      public boolean exists()
      Internal API, do not use. Returns true if the object exists (existing object can be unresolvable because of permissions). The object is resolved, if it exists, as a side effect.
    • adapt

      public Object adapt(Class targetClass)
      Specified by:
      adapt in interface IAdaptable
      Returns:
      The incance of targetClass representing this object or null if adaptation is not possible.
    • hashCode

      public int hashCode()
      For temporary objects (uri==null) the hash code is taken from parent class.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      For temporary objects (uri==null) the logic is taken from parent class, the others compare the uris.
      Overrides:
      equals in class Object
    • getDataSvc

      public IDataService getDataSvc()
      Description copied from interface: IPObject
      This is a convenience method, so that everyone, who has a IPObject in hand, can easily get the IDataService as well and doesn't have to do some additional work (since the IPObject has this reference anyway.
      Specified by:
      getDataSvc in interface IPObject
      Returns:
      The data service this object is bound to.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setCachedDynamicRoles

      public void setCachedDynamicRoles(String user, Collection<String> roles)
    • getCachedDynamicRoles

      public Collection<String> getCachedDynamicRoles(String user)
    • isInCustomSet

      public boolean isInCustomSet(@Nullable String customSet)
      Returns:
      whether this object belongs to given custom set (specified by Lucene query)
      Since:
      3.8.1
      See Also:
    • setInCustomSet

      public void setInCustomSet(@NotNull String customSet, boolean isIn)
      Internal API, do not use.
      Since:
      3.10.1
    • setEnumerationValue

      public void setEnumerationValue(String key, String value)
      Description copied from interface: IPObject
      Sets the enumeration value of given field.

      Shortcut for combination of IPObject.getEnumerationOptionForField(String, String) and IPObject.setValue(String, Object).

      Specified by:
      setEnumerationValue in interface IPObject
      Parameters:
      key - field name (not null)
      value - enumeration value (option id)
    • getEnumerationOptionForField

      public IEnumOption getEnumerationOptionForField(String key, String value)
      Description copied from interface: IPObject
      Returns wrapped enumeration option for given field.
      Specified by:
      getEnumerationOptionForField in interface IPObject
      Parameters:
      key - field name (not null)
      value - option id
      Returns:
      wrapped option (null if and only if optionId is null)
      See Also:
    • getEnumerationTypeForField

      @NotNull public Optional<IEnumType> getEnumerationTypeForField(@NotNull String key)
      Specified by:
      getEnumerationTypeForField in interface IPObject
      Returns:
      the Optional IEnumType for the given field if it is of enum or multi-enum type, otherwise returns Optional.empty().
      See Also:
    • copy

      @NotNull public <T extends IPObject> com.polarion.platform.persistence.internal.model.IFieldCopier<T> copy()
      Internal method, not an API.
    • copyTo

      public void copyTo(@NotNull IPObject dest, @Nullable Set<String> includeKeys, @Nullable Set<String> excludeKeys, boolean includeAllCustomFields, @Nullable Set<String> notCopiedCustomFields, @Nullable Set<String> convertedCopiedCustomFields)
      Description copied from interface: IPObject
      Copies the content of this IPObject to a given IPObject.

      Both objects must be of the same prototype.

      New persistent objects may be created in the process.

      IPObject.save() may be called on any object (this object, the destination object or any new object) during the execution of this method. However the caller must call IPObject.save() on the destination object in order to make all changes persistent.

      The exact implementation is type-dependent.

      Specified by:
      copyTo in interface IPObject
      Parameters:
      dest - destination object (not null)
      includeKeys - which keys to include when copying (null means all); can also include custom keys
      excludeKeys - which keys to exclude when copying (null means none); can also include custom keys
      includeAllCustomFields - true if all custom fields should also be copied; if false then only those mentioned in includeKeys and not mentioned in excludeKeys are copied
      notCopiedCustomFields - custom fields that could not be copied (output); note that since 3.5.1 this is always an empty set, because the 'incompatibleCustomFields' feature is used for custom fields of this type
      convertedCopiedCustomFields - custom fields which were converted rather than exact copies (output). Since 3.5.1 this also includes incompatible custom fields.
    • getFieldType

      public IType getFieldType(String key)
      Returns type of the field regardless if it is a build in or custom field.
      Specified by:
      getFieldType in interface IPObject
      Parameters:
      key - - field key
      Returns:
      type or null when the field is not defined.
      Since:
      3.5.2
    • can

      @NotNull public IPObjectPermissions can()
      Specified by:
      can in interface IPObject
      Since:
      3.8.2
    • getFieldLabel

      @NotNull public String getFieldLabel(@NotNull String fieldId)
      Description copied from interface: IPObject
      Returns label of the field regardless if it is a built-in or custom field.
      Specified by:
      getFieldLabel in interface IPObject