You need to check if type is folder or file.

```java
.....
    private Map<String, NodeType> folderTypes;
    private Map<String, NodeType> fileTypes;
....
    @Override
    public void initialize(NamespaceRegistry registry,
                           NodeTypeManager nodeTypeManager) throws RepositoryException, IOException {
....
        folderTypes = new HashMap<String, NodeType>();
        NodeTypeIterator folders = nodeTypeManager.getNodeType(NodeType.NT_FOLDER).getSubtypes();
        while (folders.hasNext()) {
            NodeType type = (NodeType) folders.next();
            folderTypes.put(type.getName(), type);
        }
        NodeTypeIterator files = nodeTypeManager.getNodeType(NodeType.NT_FILE).getSubtypes();
        fileTypes = new HashMap<String, NodeType>();
        while (files.hasNext()) {
            NodeType type = (NodeType) files.next();
            fileTypes.put(type.getName(), type);
        }

        if (primaryType.toString().equals(NodeType.NT_FOLDER) || folderTypes.containsKey(primaryType.toString())) {
            Folder parent = (Folder) session.getObject(parentId);
            String path = parent.getPath() + "/" + name.getLocalName();
            //minimal set of parameters
            params.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value());
            params.put(PropertyIds.NAME, name.getLocalName());
            params.put(PropertyIds.PATH, path);

            if (folderTypes.containsKey(primaryType.toString())) {
                for (javax.jcr.nodetype.PropertyDefinition prop : folderTypes.get(primaryType.toString()).getPropertyDefinitions()) {
                    if (prop.isMandatory()) {
                        //TODO: Fill proper random value per each possible type
                        params.put(prop.getName(), new Object());
                    }
                }
            }

            Folder folder = parent.createFolder(params);
            return folder.getId();
        }
....
    @Override
    public String newDocumentId(String parentId, Name name, Name primaryType) {
        HashMap<String, Object> params = new HashMap();
        if (primaryType.toString().equals(NodeType.NT_FILE) || fileTypes.containsKey(primaryType.toString())) {
            Folder parent = (Folder) session.getObject(parentId);
            String path = parent.getPath() + "/" + name.getLocalName();
            //minimal set of parameters
            params.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
            params.put(PropertyIds.NAME, name.getLocalName());
            //params.put(PropertyIds.PARENT_ID, path);

            if (fileTypes.containsKey(primaryType.toString())) {
                for (javax.jcr.nodetype.PropertyDefinition prop : fileTypes.get(primaryType.toString()).getPropertyDefinitions()) {
                    if (prop.isMandatory()) {
                        //TODO: Fill proper random value per each possible type
                        params.put(prop.getName(), new Object());
                    }
                }
            }
            //TODO: check capabilities, in case of versioning supported - create new version
            //session.getRepositoryInfo().getCapabilities().getChangesCapability().
            return parent.createDocument(params, null, VersioningState.NONE).getId();
        }
```