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

protected RepositoryFileAcl getParentAcl(final Serializable id) {
    return (RepositoryFileAcl) jcrTemplate.execute(new JcrCallback() {
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            Node node = session.getNodeByIdentifier(id.toString());
            if (!node.getParent().isSame(session.getRootNode())) {
                return toAcl(session, pentahoJcrConstants, node.getParent().getIdentifier());
            } else {
                return null;
            }//from   www.  ja  va 2  s  .c  o  m
        }
    });
}

From source file:org.pentaho.agilebi.modeler.models.annotations.CreateAttribute.java

@Override
public void populate(final Map<String, Serializable> propertiesMap) {

    super.populate(propertiesMap); // let base class handle primitives, etc.

    try {//from   w w  w  .  j  av a 2s .  co m
        // correctly convert time type
        if (propertiesMap.containsKey(TIME_TYPE_ID)) {
            Serializable value = propertiesMap.get(TIME_TYPE_ID);
            if (value != null) {
                setTimeType(ModelAnnotation.TimeType.valueOf(value.toString()));
            }
        }

        // correctly convert geo type
        if (propertiesMap.containsKey(GEO_TYPE_ID)) {
            Serializable value = propertiesMap.get(GEO_TYPE_ID);
            if (value != null) {
                setGeoType(ModelAnnotation.GeoType.valueOf(value.toString()));
            }
        }
    } catch (Exception e) {
        // ignore
        logger.warning(e.getLocalizedMessage());
    }
}

From source file:org.nuxeo.template.processors.docx.WordXMLRawTemplateProcessor.java

@Override
@SuppressWarnings("rawtypes")
public Blob renderTemplate(TemplateBasedDocument templateDocument, String templateName) throws IOException {

    File workingDir = getWorkingDir();

    Blob blob = templateDocument.getTemplateBlob(templateName);
    String fileName = blob.getFilename();
    List<TemplateInput> params = templateDocument.getParams(templateName);

    try (CloseableFile source = blob.getCloseableFile()) {
        ZipUtils.unzip(source.getFile(), workingDir);
    }/*  w  ww  .  ja  v  a 2s  . c  om*/

    File xmlCustomFile = new File(workingDir.getAbsolutePath() + "/docProps/custom.xml");

    String xmlContent = FileUtils.readFileToString(xmlCustomFile, StandardCharsets.UTF_8);

    Document xmlDoc;
    try {
        xmlDoc = DocumentHelper.parseText(xmlContent);
    } catch (DocumentException e) {
        throw new IOException(e);
    }

    List nodes = xmlDoc.getRootElement().elements();

    for (Object node : nodes) {
        DefaultElement elem = (DefaultElement) node;
        if ("property".equals(elem.getName())) {
            String name = elem.attributeValue("name");
            TemplateInput param = getParamByName(name, params);
            DefaultElement valueElem = (DefaultElement) elem.elements().get(0);
            String strValue = "";
            if (param.isSourceValue()) {
                Property property = templateDocument.getAdaptedDoc().getProperty(param.getSource());
                if (property != null) {
                    Serializable value = templateDocument.getAdaptedDoc().getPropertyValue(param.getSource());
                    if (value != null) {
                        if (value instanceof Date) {
                            SimpleDateFormat wordXMLDateFormat = new SimpleDateFormat(WORD_XML_DATE_FORMAT);
                            strValue = wordXMLDateFormat.format((Date) value);
                        } else {
                            strValue = value.toString();
                        }
                    }
                }
            } else {
                if (InputType.StringValue.equals(param.getType())) {
                    strValue = param.getStringValue();
                } else if (InputType.BooleanValue.equals(param.getType())) {
                    strValue = param.getBooleanValue().toString();
                } else if (InputType.DateValue.equals(param.getType())) {
                    SimpleDateFormat wordXMLDateFormat = new SimpleDateFormat(WORD_XML_DATE_FORMAT);
                    strValue = wordXMLDateFormat.format(param.getDateValue());
                }
            }
            valueElem.setText(strValue);
        }
    }

    String newXMLContent = xmlDoc.asXML();

    File newZipFile = Framework.createTempFile("newWordXMLTemplate", ".docx");
    xmlCustomFile.delete();
    File newXMLFile = new File(xmlCustomFile.getAbsolutePath());
    FileUtils.writeStringToFile(newXMLFile, newXMLContent, StandardCharsets.UTF_8);

    File[] files = workingDir.listFiles();
    ZipUtils.zip(files, newZipFile);

    // clean up
    org.apache.commons.io.FileUtils.deleteDirectory(workingDir);

    Blob newBlob = Blobs.createBlob(newZipFile);
    Framework.trackFile(newZipFile, newBlob);
    newBlob.setFilename(fileName);

    return newBlob;
}

From source file:org.bremersee.common.security.acls.model.CommonObjectIdentityRetrievalStrategy.java

@Override
public ObjectIdentity createObjectIdentity(final Serializable id, final String type) {
    if (log.isDebugEnabled()) {
        log.debug("Creating object identity for id [{}] and type [{}] ...", id, type);
    }//from   w  w  w.  jav  a  2  s  .  c  o m
    Validate.notNull(id, "ID must not be null.");
    Validate.notBlank(type, "Type must not be null or blank.");
    ObjectIdentity objectIdentity = null;
    ObjectIdentityRetrievalStrategyInterceptor interceptor = findInterceptorByType(type);
    if (interceptor != null) {
        objectIdentity = interceptor.createObjectIdentity(id, type);
    }
    if (objectIdentity == null) {
        objectIdentity = new ObjectIdentityImpl(type, id.toString());
    }
    if (log.isDebugEnabled()) {
        log.debug("Object identity for id [{}] and type [{}] created: {}", id, type, objectIdentity);
    }
    return objectIdentity;
}

From source file:org.silverpeas.core.io.temp.TemporaryWorkspaceTranslationTest.java

@Test
public void testWorkspacePutKeyValueOnNotCreateWorkspaceAndReload() throws Exception {
    File descriptor = new File(tempPath, (SILVERPEAS_TRANSLATION_PREFIX + TEST_WORKSPACE_ID));
    Serializable serializable = new SerializableClass();
    TemporaryWorkspaceTranslation test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID);
    test.create();/*from   w  w  w. j a va  2 s  . c  o m*/
    assertThat(descriptor.exists(), is(true));

    test.put("key", "value");
    test.put("otherKey", serializable);
    assertThat(test.get("key"), is("value"));
    assertThat(test.get("otherKey"), not(sameInstance(serializable)));
    assertThat(test.get("otherKey").toString(), is(serializable.toString()));

    assertThat(FileUtils.readFileToString(descriptor), containsString(TRANSLATION_ID_KEY));
    assertThat(FileUtils.readFileToString(descriptor), containsString("key="));
    assertThat(FileUtils.readFileToString(descriptor), containsString("otherKey="));

    test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID);
    assertThat(test.get("key"), notNullValue());
    assertThat(test.get("otherKey"), notNullValue());
    assertThat(test.get("key"), is("value"));
    assertThat(test.get("otherKey"), not(sameInstance(serializable)));
    assertThat(test.get("otherKey").toString(), is(serializable.toString()));
}

From source file:org.pentaho.platform.repository2.unified.ExceptionLoggingDecorator.java

@Deprecated
public List<RepositoryFile> getChildren(final Serializable folderId, final String filter,
        final Boolean showHiddenFiles) {
    return getChildren(new RepositoryRequest(folderId.toString(), showHiddenFiles, -1, filter));
}

From source file:org.alfresco.repo.forum.DiscussableAspect.java

public void onCopyComplete(QName classRef, NodeRef sourceNodeRef, NodeRef targetNodeRef, boolean copyToNewNode,
        Map<NodeRef, NodeRef> copyMap) {
    Set<NodeRef> workingCopyNodeRefs = TransactionalResourceHelper.getSet(KEY_WORKING_COPIES);
    if (!workingCopyNodeRefs.contains(sourceNodeRef)) {
        // This is not one of the nodes that needs to have discussions copied over
        return;/*  www  .  jav a2 s  .c o m*/
    }

    // First check that the source node has forums
    NodeRef sourceForumNodeRef = getForum(sourceNodeRef);
    if (sourceForumNodeRef == null) {
        // Missing!  Clean the source node up!
        nodeService.removeAspect(sourceNodeRef, ForumModel.ASPECT_DISCUSSABLE);
        return;
    }

    // The aspect may or may not exist on the target node
    if (!nodeService.hasAspect(targetNodeRef, ForumModel.ASPECT_DISCUSSABLE)) {
        // Add the aspect
        nodeService.addAspect(targetNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
    }
    // Get the forum node
    NodeRef targetForumNodeRef = getForum(targetNodeRef);
    // Merge the forum topics
    List<ChildAssociationRef> topicAssocRefs = nodeService.getChildAssocs(sourceForumNodeRef,
            Collections.singleton(ForumModel.TYPE_TOPIC));
    int copied = 0;
    for (ChildAssociationRef topicAssocRef : topicAssocRefs) {
        NodeRef topicNodeRef = topicAssocRef.getChildRef();
        try {
            // work out the name for the copied topic
            String topicName;
            String topicNodeName = nodeService.getProperty(topicNodeRef, ContentModel.PROP_NAME).toString();
            Serializable labelProp = nodeService.getProperty(targetNodeRef, ContentModel.PROP_VERSION_LABEL);
            if (labelProp == null) {
                SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss");
                topicName = topicNodeName + " - " + dateFormat.format(new Date());
            } else {
                topicName = topicNodeName + " (" + labelProp.toString() + ")";
            }

            if (fileFolderService.searchSimple(targetForumNodeRef, topicName) != null) {
                // A topic with that name already exists
                continue;
            }
            fileFolderService.copy(topicNodeRef, targetForumNodeRef, topicName);
            copied++;
        } catch (FileExistsException e) {
            // We checked for this, so this is a concurrency condition
            throw new ConcurrencyFailureException("Target topic exists: " + e.getMessage(), e);
        } catch (FileNotFoundException e) {
            // The node was there, but now it's gone
            throw new ConcurrencyFailureException("Forum was deleted: " + e.getMessage(), e);
        }
    }
}

From source file:org.silverpeas.core.io.temp.TestTemporaryWorkspaceTranslation.java

@Test
public void testWorkspacePutKeyValueOnNotCreateWorkspaceAndReload() throws Exception {
    File descriptor = new File(tempPath, (SILVERPEAS_TRANSLATION_PREFIX + TEST_WORKSPACE_ID));
    Serializable serializable = new SerializableClass();
    TemporaryWorkspaceTranslation test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID);
    test.create();/*  ww  w  .j  a v a  2 s  . c o m*/
    assertThat(descriptor.exists(), is(true));

    test.put("key", "value");
    test.put("otherKey", serializable);
    assertThat((String) test.get("key"), is("value"));
    assertThat(test.get("otherKey"), not(sameInstance(serializable)));
    assertThat(test.get("otherKey").toString(), is(serializable.toString()));

    assertThat(FileUtils.readFileToString(descriptor), containsString(TRANSLATION_ID_KEY));
    assertThat(FileUtils.readFileToString(descriptor), containsString("key="));
    assertThat(FileUtils.readFileToString(descriptor), containsString("otherKey="));

    test = TemporaryWorkspaceTranslation.from(TEST_WORKSPACE_ID);
    assertThat(test.get("key"), notNullValue());
    assertThat(test.get("otherKey"), notNullValue());
    assertThat((String) test.get("key"), is("value"));
    assertThat(test.get("otherKey"), not(sameInstance(serializable)));
    assertThat(test.get("otherKey").toString(), is(serializable.toString()));
}

From source file:gov.pnnl.goss.gridappsd.testmanager.TestManagerImpl.java

@Start
public void start() {

    try {/*w w  w. j av  a 2s  .c o m*/
        LogMessage logMessageObj = createLogMessage();

        logMessageObj.setLogMessage("Starting " + this.getClass().getName());
        logManager.log(logMessageObj, GridAppsDConstants.username);

        Credentials credentials = new UsernamePasswordCredentials(GridAppsDConstants.username,
                GridAppsDConstants.password);
        Client client = clientFactory.create(PROTOCOL.STOMP, credentials);

        //         String path = "/Users/jsimpson/git/adms/GOSS-GridAPPS-D/gov.pnnl.goss.gridappsd/applications/python/exampleTestConfig.json";
        //         TestConfiguration testConf = loadTestConfig(path);
        //         path = "/Users/jsimpson/git/adms/GOSS-GridAPPS-D/gov.pnnl.goss.gridappsd/applications/python/exampleTestScript.json";
        //         TestScript testScript = loadTestScript(path);
        //         
        //         requestSimulation(client, testConf, testScript);

        //         TestConfigurationImpl tc = null;
        //         
        //         TestScriptImpl ts = null;
        //         
        //TODO: Setup Figure out location of TestScripts

        //         requestSimulation(client, tc, ts);

        //TODO: Collect data from data manager
        // TODO Build queries

        //TODO: Get Simulation Results from ProcessManager

        //TODO: Compare Results

        //TODO: 

        // Is called directly from process manager Remove on message

        //TODO: subscribe to GridAppsDConstants.topic_request_prefix+/* instead of GridAppsDConstants.topic_requestSimulation
        client.subscribe(topic_requestTest, new GossResponseEvent() {

            @Override
            public void onMessage(Serializable message) {
                DataResponse event = (DataResponse) message;
                logMessageObj.setTimestamp(new Date().getTime());
                logMessageObj.setLogMessage(
                        "Recevied message: " + event.getData() + " on topic " + event.getDestination());
                logManager.log(logMessageObj, GridAppsDConstants.username);

                RequestTest reqTest = RequestTest.parse(message.toString());

                TestConfiguration testConfig = loadTestConfig(reqTest.getTestConfigPath());

                TestScript testScript = loadTestScript(reqTest.getTestScriptPath());

                try {
                    requestSimulation(client, testConfig, testScript);
                } catch (JMSException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

        });
    } catch (Exception e) {
        log.error("Error in process manager", e);
    }
}

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

public static Map<String, Serializable> getFileMetadata(final Session session, final Serializable fileId)
        throws ItemNotFoundException, RepositoryException {
    Map<String, Serializable> values = new HashMap<String, Serializable>();
    String prefix = session.getNamespacePrefix(PentahoJcrConstants.PHO_NS);
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
    String metadataNodeName = pentahoJcrConstants.getPHO_METADATA();
    Node metadataNode = null;/*from  w w  w . jav a  2 s.c  o m*/
    try {
        metadataNode = NodeHelper.checkGetNode(fileNode, metadataNodeName);
    } catch (PathNotFoundException pathNotFound) { // No meta on this return an empty Map
        return values;
    }
    PropertyIterator iter = metadataNode.getProperties(prefix + ":*"); //$NON-NLS-1$
    while (iter.hasNext()) {
        Property property = iter.nextProperty();
        String key = property.getName().substring(property.getName().indexOf(':') + 1);
        Serializable value = null;
        switch (property.getType()) {
        case PropertyType.STRING:
            value = property.getString();
            break;
        case PropertyType.DATE:
            value = property.getDate();
            break;
        case PropertyType.DOUBLE:
            value = property.getDouble();
            break;
        case PropertyType.LONG:
            value = property.getLong();
            break;
        case PropertyType.BOOLEAN:
            value = property.getBoolean();
            break;
        }
        if (value != null) {
            values.put(key, value);
        }
    }

    return values;
}