Example usage for java.io Serializable toString

List of usage examples for java.io Serializable toString

Introduction

In this page you can find the example usage for java.io Serializable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDaoInst.java

public void deleteFileAtVersion(final Session session, final Serializable fileId, final Serializable versionId)
        throws RepositoryException {
    if (!hasAccess(session, fileId, RepositoryFilePermission.DELETE)) {
        return;/*from  ww w.  j a  va 2s .  c om*/
    }
    Node fileToDeleteNode = session.getNodeByIdentifier(fileId.toString());
    session.getWorkspace().getVersionManager().getVersionHistory(fileToDeleteNode.getPath())
            .removeVersion(versionId.toString());
    session.save();
}

From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java

/**
 * Conditionally checks in node representing file if node is versionable.
 *///from   w ww .j av a  2 s  . c o m
public static void checkinNearestVersionableFileIfNecessary(final Session session,
        final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final String versionMessage,
        final Date versionDate, final boolean aclOnlyChange) throws RepositoryException {
    // file could be null meaning the caller is using null as the parent folder; that's OK; in this case the node
    // in
    // question would be the repository root node and that is never versioned
    if (fileId != null) {
        Node node = session.getNodeByIdentifier(fileId.toString());
        checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, node, versionMessage,
                versionDate, aclOnlyChange);
    }
}

From source file:org.alfresco.repo.content.metadata.TikaImageMetadataExtracter.java

protected void addTikaProperties(Property[] tikaProperties, Metadata metadata,
        Map<String, Serializable> properties) {
    for (Property tikaProperty : tikaProperties) {
        Serializable metadataValue = null;
        if (metadata.get(tikaProperty) != null) {
            if (tikaProperty.getValueType() == Property.ValueType.DATE) {
                metadataValue = metadata.getDate(tikaProperty);
            } else if (tikaProperty.getValueType() == Property.ValueType.INTEGER) {
                metadataValue = metadata.getInt(tikaProperty);
            } else if (metadata.isMultiValued(tikaProperty.getName())) {
                metadataValue = metadata.getValues(tikaProperty.getName());
            } else {
                metadataValue = metadata.get(tikaProperty);
            }// w  ww.  java  2 s.  co m
        }
        if (logger.isTraceEnabled()) {
            String logValue = null;
            if (metadataValue != null) {
                logValue = metadataValue.toString();
            }
            logger.trace(tikaProperty.getName() + "=" + logValue);
        }
        if (metadataValue != null) {
            putRawValue(tikaProperty.getName(), metadataValue, properties);
        }
    }
}

From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDaoInst.java

private RepositoryFile internalGetFileById(Session session, final Serializable fileId, final boolean loadMaps,
        final IPentahoLocale locale) throws RepositoryException {
    Assert.notNull(fileId);/*from ww  w .  j a v a  2  s . c o m*/
    PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    RepositoryFile file = fileNode != null
            ? JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper,
                    fileNode, loadMaps, locale)
            : null;
    return file;
}

From source file:org.sakaiproject.genericdao.hibernate.HibernateGenericDao.java

@SuppressWarnings("unchecked")
public <T> T findById(Class<T> type, Serializable id) {
    checkClass(type);//from  www . j  ava  2 s  .c  o  m
    if (id == null) {
        throw new IllegalArgumentException("id must be set to find persistent object");
    }

    T entity = null;
    // check cache first
    String key = id.toString();
    String cacheName = getCacheName(type);
    if (getCacheProvider().exists(cacheName, key)) {
        entity = (T) getCacheProvider().get(cacheName, key);
    } else {
        // not in cache so go to the DB

        // before interceptor
        String operation = "findById";
        beforeRead(operation, type, new Serializable[] { id }, null);

        entity = baseFindById(type, id);

        // now put the item in the cache
        getCacheProvider().put(cacheName, key, entity);

        // after interceptor
        afterRead(operation, type, new Serializable[] { id }, null, new Object[] { entity });
    }
    return entity;
}

From source file:ddf.catalog.source.opensearch.OpenSearchSource.java

@Override
public ResourceResponse retrieveResource(URI uri, Map<String, Serializable> requestProperties)
        throws ResourceNotFoundException, ResourceNotSupportedException, IOException {

    final String methodName = "retrieveResource";
    LOGGER.trace("ENTRY: {}", methodName);

    if (requestProperties == null) {
        throw new ResourceNotFoundException("Could not retrieve resource with null properties.");
    }/*w  w  w .  j  a  v a 2s  .c o m*/

    Serializable serializableId = requestProperties.get(Metacard.ID);

    if (serializableId != null) {
        String metacardId = serializableId.toString();
        WebClient restClient = null;
        restClient = newRestClient(null, metacardId, true, null);
        return resourceReader.retrieveResource(restClient.getCurrentURI(), requestProperties);
    }

    LOGGER.trace("EXIT: {}", methodName);
    throw new ResourceNotFoundException(COULD_NOT_RETRIEVE_RESOURCE_MESSAGE);
}

From source file:org.grails.datastore.mapping.riak.engine.RiakEntityPersister.java

@Override
protected Map retrieveEntry(PersistentEntity persistentEntity, String family, Serializable key) {
    // Not sure this check is actually necessary, but I was seeing null keys being passed
    // during tests, so handle it explicitly.
    if (null == key) {
        return null;
    }//from w w  w.  j ava  2s.c  o m

    Set<String> descendants = null;
    RiakValue<Map> v = null;

    // Check for any descendants this entity might have.
    String bucket = persistentEntity.getName() + ".metadata";
    if (riakTemplate.containsKey(bucket, DESCENDANTS)) {
        descendants = riakTemplate.getAsType(bucket, DESCENDANTS, Set.class);
        v = riakTemplate.getWithMetaData(family,
                (key instanceof Long ? (Long) key : Long.parseLong(key.toString())), Map.class);
        if (log.isDebugEnabled()) {
            log.debug(String.format("retrieveEntry(): entity=%s, family=%s, key=%s, values=%s",
                    persistentEntity.getName(), family, key, v));
        }
    }

    if (null == v && null != descendants) {
        // Search through all descendants, as well.
        for (String d : descendants) {
            v = riakTemplate.getWithMetaData(d,
                    (key instanceof Long ? (Long) key : Long.parseLong(key.toString())), Map.class);
            if (null != v) {
                break;
            }
        }
    }

    return (null != v ? v.get() : null);
}

From source file:ddf.catalog.impl.operations.ResourceOperations.java

@SuppressWarnings("javadoc")
ResourceResponse getResource(ResourceRequest resourceRequest, boolean isEnterprise, String resourceSiteName,
        boolean fanoutEnabled) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    ResourceResponse resourceResponse = null;
    ResourceRequest resourceReq = resourceRequest;
    ResourceRetriever retriever = null;//from   www.ja va  2 s.  com

    if (fanoutEnabled) {
        isEnterprise = true;
    }

    if (resourceSiteName == null && !isEnterprise) {
        throw new ResourceNotFoundException("resourceSiteName cannot be null when obtaining resource.");
    }

    validateGetResourceRequest(resourceReq);
    try {
        resourceReq = preProcessPreAuthorizationPlugins(resourceReq);
        resourceReq = processPreResourcePolicyPlugins(resourceReq);
        resourceReq = processPreResourceAccessPlugins(resourceReq);
        resourceReq = processPreResourcePlugins(resourceReq);

        Map<String, Serializable> requestProperties = resourceReq.getProperties();
        LOGGER.debug("Attempting to get resource from siteName: {}", resourceSiteName);
        // At this point we pull out the properties and use them.
        Serializable sourceIdProperty = requestProperties.get(ResourceRequest.SOURCE_ID);
        final String namedSource = (sourceIdProperty != null) ? sourceIdProperty.toString() : resourceSiteName;

        Serializable enterpriseProperty = requestProperties.get(ResourceRequest.IS_ENTERPRISE);
        if (enterpriseProperty != null && Boolean.parseBoolean(enterpriseProperty.toString())) {
            isEnterprise = true;
        }

        // check if the resourceRequest has an ID only
        // If so, the metacard needs to be found and the Resource URI
        StringBuilder resolvedSourceIdHolder = new StringBuilder();

        ResourceInfo resourceInfo = getResourceInfo(resourceReq, namedSource, isEnterprise,
                resolvedSourceIdHolder, requestProperties, fanoutEnabled);
        if (resourceInfo == null) {
            throw new ResourceNotFoundException("Resource could not be found for the given attribute value: "
                    + resourceReq.getAttributeValue());
        }
        final URI responseURI = resourceInfo.getResourceUri();
        final Metacard metacard = resourceInfo.getMetacard();

        final String resolvedSourceId = resolvedSourceIdHolder.toString();
        LOGGER.debug("resolvedSourceId = {}", resolvedSourceId);
        LOGGER.debug("ID = {}", getId());

        // since resolvedSourceId specifies what source the product
        // metacard resides on, we can just
        // change resourceSiteName to be that value, and then the
        // following if-else statements will
        // handle retrieving the product on the correct source
        final String resourceSourceName = (isEnterprise) ? resolvedSourceId : namedSource;

        // retrieve product from specified federated site if not in cache
        if (!resourceSourceName.equals(getId())) {
            LOGGER.debug("Searching federatedSource {} for resource.", resourceSourceName);
            LOGGER.debug("metacard for product found on source: {}", resolvedSourceId);

            final List<FederatedSource> sources = frameworkProperties.getFederatedSources().stream()
                    .filter(e -> e.getId().equals(resourceSourceName)).collect(Collectors.toList());

            if (!sources.isEmpty()) {
                if (sources.size() != 1) {
                    LOGGER.debug("Found multiple federatedSources for id: {}", resourceSourceName);
                }
                FederatedSource source = sources.get(0);
                LOGGER.debug("Adding federated site to federated query: {}", source.getId());
                LOGGER.debug("Retrieving product from remote source {}", source.getId());
                retriever = new RemoteResourceRetriever(source, responseURI, requestProperties);
            } else {
                LOGGER.debug("Could not find federatedSource: {}", resourceSourceName);
            }
        } else {
            LOGGER.debug("Retrieving product from local source {}", resourceSourceName);
            retriever = new LocalResourceRetriever(frameworkProperties.getResourceReaders(), responseURI,
                    metacard, requestProperties);
        }

        try {
            resourceResponse = frameworkProperties.getDownloadManager().download(resourceRequest, metacard,
                    retriever);
        } catch (DownloadException e) {
            LOGGER.info("Unable to download resource", e);
        }

        resourceResponse = putPropertiesInResponse(resourceRequest, resourceResponse);

        resourceResponse = validateFixGetResourceResponse(resourceResponse, resourceReq);

        resourceResponse = postProcessPreAuthorizationPlugins(resourceResponse, metacard);
        resourceResponse = processPostResourcePolicyPlugins(resourceResponse, metacard);
        resourceResponse = processPostResourceAccessPlugins(resourceResponse, metacard);
        resourceResponse = processPostResourcePlugins(resourceResponse);

        resourceResponse.getProperties().put(Constants.METACARD_PROPERTY, metacard);
    } catch (DataUsageLimitExceededException e) {
        LOGGER.info("RuntimeException caused by: ", e);
        throw e;
    } catch (RuntimeException e) {
        LOGGER.info("RuntimeException caused by: ", e);
        throw new ResourceNotFoundException("Unable to find resource");
    } catch (StopProcessingException e) {
        LOGGER.info("Resource not supported", e);
        throw new ResourceNotSupportedException(FAILED_BY_GET_RESOURCE_PLUGIN + e.getMessage());
    }

    return resourceResponse;
}

From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileAclDao.java

protected RepositoryFileAcl internalUpdateAcl(final Session session,
        final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final RepositoryFileAcl acl)
        throws RepositoryException {
    if (isKioskEnabled()) {
        throw new RuntimeException(
                Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED")); //$NON-NLS-1$
    }//from w  ww. j  av a 2 s.c  o m

    DefaultPermissionConversionHelper permissionConversionHelper = new DefaultPermissionConversionHelper(
            session);
    Node node = session.getNodeByIdentifier(fileId.toString());
    if (node == null) {
        throw new RepositoryException(Messages.getInstance()
                .getString("JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND", fileId.toString())); //$NON-NLS-1$
    }
    String absPath = node.getPath();
    AccessControlManager acMgr = session.getAccessControlManager();
    AccessControlList acList = getAccessControlList(acMgr, absPath);

    // clear all entries
    AccessControlEntry[] acEntries = acList.getAccessControlEntries();
    for (int i = 0; i < acEntries.length; i++) {
        acList.removeAccessControlEntry(acEntries[i]);
    }

    JcrRepositoryFileAclUtils.setAclMetadata(session, absPath, acList,
            new AclMetadata(acl.getOwner().getName(), acl.isEntriesInheriting()));

    // add entries to now empty list but only if not inheriting; force user to start with clean slate
    boolean adminPrincipalExist = false;
    ITenant principalTenant = null;
    if (!acl.isEntriesInheriting()) {
        for (RepositoryFileAce ace : acl.getAces()) {
            Principal principal = null;
            if (RepositoryFileSid.Type.ROLE == ace.getSid().getType()) {
                String principalName = JcrTenantUtils.getRoleNameUtils()
                        .getPrincipleName(ace.getSid().getName());
                if (tenantAdminAuthorityName.equals(principalName)) {
                    adminPrincipalExist = true;
                }
                principal = new SpringSecurityRolePrincipal(
                        JcrTenantUtils.getTenantedRole(ace.getSid().getName()));
            } else {
                principal = new SpringSecurityUserPrincipal(
                        JcrTenantUtils.getTenantedUser(ace.getSid().getName()));
            }
            acList.addAccessControlEntry(principal,
                    permissionConversionHelper.pentahoPermissionsToPrivileges(session, ace.getPermissions()));
        }
        if (!adminPrincipalExist) {
            if (acl.getAces() != null && acl.getAces().size() > 0) {
                principalTenant = JcrTenantUtils.getRoleNameUtils()
                        .getTenant(acl.getAces().get(0).getSid().getName());
            }

            if (principalTenant == null || principalTenant.getId() == null) {
                principalTenant = JcrTenantUtils.getTenant();
            }

            List<RepositoryFilePermission> permissionList = new ArrayList<RepositoryFilePermission>();
            permissionList.add(RepositoryFilePermission.ALL);
            Principal adminPrincipal = new SpringSecurityRolePrincipal(JcrTenantUtils.getRoleNameUtils()
                    .getPrincipleId(principalTenant, tenantAdminAuthorityName));
            acList.addAccessControlEntry(adminPrincipal, permissionConversionHelper
                    .pentahoPermissionsToPrivileges(session, EnumSet.copyOf(permissionList)));
        }

    }
    acMgr.setPolicy(absPath, acList);
    session.save();
    return getAcl(fileId);

}