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.JcrRepositoryFileUtils.java

public static Node createFolderNode(final Session session, final PentahoJcrConstants pentahoJcrConstants,
        final Serializable parentFolderId, final RepositoryFile folder) throws RepositoryException {
    // Not need to check the name if we encoded it
    // checkName( folder.getName() );
    Node parentFolderNode;/*from  w  ww . j  a  va  2 s  .c o m*/
    if (parentFolderId != null) {
        parentFolderNode = session.getNodeByIdentifier(parentFolderId.toString());
    } else {
        parentFolderNode = session.getRootNode();
    }

    // guard against using a file retrieved from a more lenient session inside a more strict session
    Assert.notNull(parentFolderNode);

    String encodedfolderName = JcrStringHelper.fileNameEncode(folder.getName());
    Node folderNode = parentFolderNode.addNode(encodedfolderName,
            pentahoJcrConstants.getPHO_NT_PENTAHOFOLDER());
    folderNode.setProperty(pentahoJcrConstants.getPHO_HIDDEN(), folder.isHidden());
    folderNode.setProperty(pentahoJcrConstants.getPHO_ACLNODE(), folder.isAclNode());
    // folderNode.setProperty(pentahoJcrConstants.getPHO_TITLE(), folder.getTitle());
    Node localeNodes = null;
    if (folder.getTitle() != folder.getName()) { // Title is different from the name
        localeNodes = folderNode.addNode(pentahoJcrConstants.getPHO_LOCALES(),
                pentahoJcrConstants.getPHO_NT_LOCALE());
        Map<String, Properties> localPropertiesMap = new HashMap<String, Properties>();
        String defaultLocale = LocaleHelper.getLocale().toString();
        Properties titleProps = new Properties();
        titleProps.put("file.title", folder.getTitle());
        localPropertiesMap.put(defaultLocale, titleProps);
        setLocalePropertiesMap(session, pentahoJcrConstants, localeNodes, localPropertiesMap);
    }
    if (folder.isVersioned()) {
        // folderNode.setProperty(addPentahoPrefix(session, PentahoJcrConstants.PENTAHO_VERSIONED), true);
        folderNode.addMixin(pentahoJcrConstants.getPHO_MIX_VERSIONABLE());
    }

    folderNode.addNode(pentahoJcrConstants.getPHO_METADATA(), JcrConstants.NT_UNSTRUCTURED);
    folderNode.addMixin(pentahoJcrConstants.getMIX_REFERENCEABLE());
    return folderNode;
}

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

/**
 * Conditionally checks out node representing file if node is versionable.
 *//*ww  w. j a v  a2 s  .c om*/
public static void checkoutNearestVersionableFileIfNecessary(final Session session,
        final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) 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());
        checkoutNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, node);
    }
}

From source file:ddf.catalog.source.solr.DynamicSchemaResolver.java

/**
 * Given xml as a string, this method will parse out element text and CDATA text. It separates
 * each by one space character.//from   ww w.j ava  2  s. com
 *
 * @param xmlDatas List of XML as {@code String}
 * @return parsed CDATA and element text
 */
protected List<String> parseTextFrom(List<Serializable> xmlDatas) {

    StringBuilder builder = new StringBuilder();
    List<String> parsedTexts = new ArrayList<>();
    XMLStreamReader xmlStreamReader = null;
    StringReader sr = null;
    long starttime = System.currentTimeMillis();

    try {
        for (Serializable xmlData : xmlDatas) {
            // xml parser does not handle leading whitespace
            sr = new StringReader(xmlData.toString());
            xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(sr);

            while (xmlStreamReader.hasNext()) {
                int event = xmlStreamReader.next();

                if (event == XMLStreamConstants.CHARACTERS || event == XMLStreamConstants.CDATA) {

                    String text = xmlStreamReader.getText();

                    if (StringUtils.isNotBlank(text)) {
                        builder.append(" ").append(text.trim());
                    }

                }
                if (event == XMLStreamConstants.START_ELEMENT) {
                    for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++) {

                        String text = xmlStreamReader.getAttributeValue(i);

                        if (StringUtils.isNotBlank(text)) {
                            builder.append(" ").append(text.trim());
                        }
                    }
                }
            }
            parsedTexts.add(builder.toString());
            builder.setLength(0);
        }
    } catch (XMLStreamException e1) {
        LOGGER.warn("Failure occurred in parsing the xml data. No data has been stored or indexed.", e1);
    } finally {
        IOUtils.closeQuietly(sr);
        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.close();
            } catch (XMLStreamException e) {
                LOGGER.debug("Exception closing XMLStreamReader", e);
            }
        }
    }
    long endTime = System.currentTimeMillis();

    LOGGER.debug("Parsing took {} ms", endTime - starttime);

    return parsedTexts;
}

From source file:org.bonitasoft.forms.server.api.impl.FormWorkflowAPIImplIT.java

@Test
public void testExecuteActionsAndTerminateWithAPIAccessor() throws Exception {
    final IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
    Assert.assertTrue("no pending user task instances are found", new WaitUntil(50, 3000) {

        @Override// w  w w  .  j a v a2  s  .  co m
        protected boolean check() throws Exception {
            return processAPI.getPendingHumanTaskInstances(getSession().getUserId(), 0, 10, null).size() >= 1;
        }
    }.waitUntil());
    HumanTaskInstance humanTaskInstance = processAPI
            .getPendingHumanTaskInstances(getSession().getUserId(), 0, 1, ActivityInstanceCriterion.NAME_ASC)
            .get(0);
    final Map<String, FormFieldValue> fieldValues = new HashMap<String, FormFieldValue>();
    final List<FormAction> formActions = new ArrayList<FormAction>();
    final Expression apiAccessorExpression = new Expression("apiAccessor", "apiAccessor",
            ExpressionType.TYPE_ENGINE_CONSTANT.name(), APIAccessor.class.getName(), null,
            new ArrayList<Expression>());
    final Expression processInstanceIdExpression = new Expression("processInstanceId", "processInstanceId",
            ExpressionType.TYPE_ENGINE_CONSTANT.name(), Long.class.getName(), null,
            new ArrayList<Expression>());
    final ArrayList<Expression> dependencyExpressions = new ArrayList<Expression>();
    dependencyExpressions.add(apiAccessorExpression);
    dependencyExpressions.add(processInstanceIdExpression);
    final Expression fieldExpression = new Expression(null,
            "apiAccessor.getProcessAPI().getProcessDataInstance(\"Application\", processInstanceId).getValue().toString()",
            ExpressionType.TYPE_READ_ONLY_SCRIPT.name(), String.class.getName(), "GROOVY",
            dependencyExpressions);
    formActions.add(new FormAction(ActionType.ASSIGNMENT, "Application", LeftOperand.TYPE_DATA, "=", null,
            fieldExpression, "submitButtonId", null));
    processAPI.assignUserTask(humanTaskInstance.getId(), getSession().getUserId());
    api.executeActionsAndTerminate(getSession(), getSession().getUserId(), humanTaskInstance.getId(),
            fieldValues, formActions, Locale.ENGLISH, "submitButtonId", new HashMap<String, Serializable>());
    Assert.assertTrue("no pending user task instances are found", new WaitUntil(50, 3000) {

        @Override
        protected boolean check() throws Exception {
            return processAPI.getPendingHumanTaskInstances(FormWorkflowAPIImplIT.this.getSession().getUserId(),
                    0, 10, null).size() >= 1;
        }
    }.waitUntil());
    humanTaskInstance = processAPI
            .getPendingHumanTaskInstances(getSession().getUserId(), 0, 1, ActivityInstanceCriterion.NAME_ASC)
            .get(0);
    final String activityName = humanTaskInstance.getName();
    Assert.assertNotNull(activityName);
    Assert.assertEquals("Approval", activityName);
    final Serializable variableValue = processAPI.getProcessDataInstance("Application", processInstanceID)
            .getValue();
    Assert.assertEquals("Word", variableValue.toString());
}

From source file:org.ambraproject.testutils.DummyHibernateDataStore.java

@Override
public String store(Object object) {
    try {//from   w  w w .j a  v  a  2 s  . c om
        return hibernateTemplate.save(object).toString();
    } catch (Exception e) {
        //for constraint violation exceptions, just check if the object already exists in the db,
        // so we can reuse data providers and call store() multiple times
        Serializable storedId = getStoredId(object);
        if (storedId != null) {
            String idPropertyName = allClassMetadata.get(object.getClass().getName())
                    .getIdentifierPropertyName();
            String idSetterName = "set" + idPropertyName.substring(0, 1).toUpperCase()
                    + idPropertyName.substring(1);
            //set the id on the object
            try {
                object.getClass().getMethod(idSetterName, storedId.getClass()).invoke(object, storedId);
            } catch (Exception e1) {
                //do nothing
            }
            return storedId.toString();
        } else {
            return null;
        }
    }
}

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

public void restoreFileAtVersion(final Session session, final Serializable fileId, final Serializable versionId,
        final String versionMessage) throws ItemNotFoundException, RepositoryException {
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    session.getWorkspace().getVersionManager().restore(fileNode.getPath(), versionId.toString(), true);
}

From source file:it.geosolutions.geobatch.services.jmx.JMXServiceManager.java

/**
 * create the configured action on the remote GeoBatch server through the JMX connection
 * /*from   w  w  w  .j a  v a2 s .  c o m*/
 * @param config A map containing the list of needed parameters, inputs and outputs used by the action
 * @throws Exception if:
 *         <ul>
 *         <li>the passed map is null</li>
 *         <li>the passed map doesn't contains needed keys</li>
 *         <li>the connection is lost</li>
 *         </ul>
 */
@Override
@org.springframework.jmx.export.annotation.ManagedOperation(description = "runConsumer - used to run a consumer")
@ManagedOperationParameters({
        @ManagedOperationParameter(name = "jmxConsumer", description = "A map containing the list of needed parameters, inputs and outputs used by the action") })
public void runConsumer(String uuid, Serializable event) throws Exception {

    if (uuid == null || event == null) {
        throw new IllegalArgumentException(
                "Unable to run using null arguments: uuid=" + uuid + " event=" + event);
    }

    EventConsumer consumer = getConsumer(uuid);

    // ///////// SET INPUTS
    if (event instanceof File)
        consumer.consume(new FileSystemEvent(File.class.cast(event), FileSystemEventType.FILE_ADDED));
    else if (event instanceof String)
        consumer.consume(new FileSystemEvent(new File(event.toString()), FileSystemEventType.FILE_ADDED));
    else
        throw new IllegalArgumentException("Unable to use the incoming event: bad type ->" + event.getClass());
    // ///////// RUN CONSUMER
    // execute
    flowManager.getExecutor().submit(consumer);
}

From source file:com.clican.pluto.fsm.model.Variable.java

public void setValue(Serializable value) {
    this.value = value;
    if (value == null) {
        this.persistentValue = null;
        this.classType = null;
        return;/*from  ww  w .j ava 2s .  com*/
    }
    this.classType = value.getClass().getName();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    if (value instanceof Date) {
        this.persistentValue = sdf.format((Date) value);
    } else if (value instanceof Calendar) {
        this.persistentValue = sdf.format(((Calendar) value).getTime());
    } else if (value instanceof Number) {
        this.persistentValue = value.toString();
    } else if (value instanceof String) {
        this.persistentValue = value.toString();
    } else {
        this.persistentValue = value.toString();
    }
}

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

public boolean canUnlockFile(final Session session, final Serializable fileId)
        throws ItemNotFoundException, RepositoryException {
    PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath());
    return lockHelper.canUnlock(session, pentahoJcrConstants, lock);
}

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

public List<RepositoryFile> getReferrers(Session session, final Serializable fileId)
        throws ItemNotFoundException, RepositoryException {
    PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);

    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    // guard against using a file retrieved from a more lenient session inside a more strict session
    Assert.notNull(fileNode);//from ww w .j  a  v a 2s.c o  m

    Set<RepositoryFile> referrers = new HashSet<RepositoryFile>();
    PropertyIterator refIter = fileNode.getReferences();
    if (refIter.hasNext()) {
        while (refIter.hasNext()) {
            // for each referrer property, march up the tree until we find the file node to which the property
            // belongs
            RepositoryFile referrer = getReferrerFile(session, pentahoJcrConstants, refIter.nextProperty());
            if (referrer != null) {
                referrers.add(referrer);
            }
        }
    }
    session.save();
    return new ArrayList<RepositoryFile>(referrers);
}