-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '5/imports' into 3/next-in-cs
- Loading branch information
Showing
108 changed files
with
16,805 additions
and
0 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
hmdb/src/main/java/com/enonic/app/hmdb/initializer/CreateContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package com.enonic.app.hmdb.initializer; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.function.Supplier; | ||
|
||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.FrameworkUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.enonic.xp.app.ApplicationKey; | ||
import com.enonic.xp.content.ContentConstants; | ||
import com.enonic.xp.content.ContentPath; | ||
import com.enonic.xp.content.ContentService; | ||
import com.enonic.xp.context.Context; | ||
import com.enonic.xp.context.ContextAccessor; | ||
import com.enonic.xp.context.ContextBuilder; | ||
import com.enonic.xp.export.ExportService; | ||
import com.enonic.xp.export.ImportNodesParams; | ||
import com.enonic.xp.export.NodeImportResult; | ||
import com.enonic.xp.index.IndexService; | ||
import com.enonic.xp.lib.content.BaseContextHandler; | ||
import com.enonic.xp.node.NodePath; | ||
import com.enonic.xp.project.ProjectName; | ||
import com.enonic.xp.script.bean.BeanContext; | ||
import com.enonic.xp.security.RoleKeys; | ||
import com.enonic.xp.security.User; | ||
import com.enonic.xp.security.auth.AuthenticationInfo; | ||
import com.enonic.xp.vfs.VirtualFile; | ||
import com.enonic.xp.vfs.VirtualFiles; | ||
|
||
public class CreateContent | ||
extends BaseContextHandler | ||
{ | ||
private String projectName; | ||
|
||
private Supplier<ContentService> contentService; | ||
|
||
private Supplier<ExportService> exportService; | ||
|
||
private Supplier<IndexService> indexService; | ||
|
||
private final Logger LOG = LoggerFactory.getLogger( CreateContent.class ); | ||
|
||
@Override | ||
protected Boolean doExecute() | ||
{ | ||
if ( this.indexService.get().isMaster() ) | ||
{ | ||
runAs( createInitContext(), () -> { | ||
doInitialize(); | ||
return null; | ||
} ); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private Context createInitContext() | ||
{ | ||
|
||
return ContextBuilder.from( ContextAccessor.current() ). | ||
authInfo( AuthenticationInfo.create().principals( RoleKeys.CONTENT_MANAGER_ADMIN ).user( User.ANONYMOUS ).build() ). | ||
branch( ContentConstants.BRANCH_DRAFT ). | ||
repositoryId( ProjectName.from(this.projectName).getRepoId() ). | ||
build(); | ||
} | ||
|
||
private void doInitialize() | ||
{ | ||
|
||
final ContentPath demoSitePath = ContentPath.from( "/hmdb" ); | ||
if ( hasContent( demoSitePath ) ) | ||
{ | ||
return; | ||
} | ||
|
||
final Bundle bundle = FrameworkUtil.getBundle( this.getClass() ); | ||
final ApplicationKey appKey = ApplicationKey.from( bundle ); | ||
|
||
final VirtualFile source = VirtualFiles.from( bundle, "/import" ); | ||
final VirtualFile xsltTransformer = VirtualFiles.from( bundle, "/import/replace_app.xsl" ); | ||
|
||
final NodeImportResult nodeImportResult = this.exportService.get().importNodes( ImportNodesParams.create(). | ||
source( source ). | ||
targetNodePath( NodePath.create( "/content" ).build() ). | ||
includeNodeIds( true ). | ||
includePermissions( false ). | ||
dryRun( false ). | ||
xslt( xsltTransformer ). | ||
xsltParam( "applicationId", appKey.toString() ). | ||
build() ); | ||
|
||
logImport( nodeImportResult ); | ||
} | ||
|
||
private void logImport( final NodeImportResult nodeImportResult ) | ||
{ | ||
LOG.info( "-------------------" ); | ||
LOG.info( "Imported nodes:" ); | ||
for ( final NodePath nodePath : nodeImportResult.getAddedNodes() ) | ||
{ | ||
LOG.info( nodePath.toString() ); | ||
} | ||
|
||
LOG.info( "-------------------" ); | ||
LOG.info( "Binaries:" ); | ||
nodeImportResult.getExportedBinaries().forEach( LOG::info ); | ||
|
||
LOG.info( "-------------------" ); | ||
LOG.info( "Errors:" ); | ||
for ( final NodeImportResult.ImportError importError : nodeImportResult.getImportErrors() ) | ||
{ | ||
final Throwable reconstructed = new Throwable( "Reconstructed stacktrace" ); | ||
reconstructed.setStackTrace( importError.getStacktrace() ); | ||
LOG.error( importError.getMessage(), importError.getException(), reconstructed ); | ||
} | ||
} | ||
|
||
private boolean hasContent( final ContentPath path ) | ||
{ | ||
try | ||
{ | ||
return this.contentService.get().getByPath( path ) != null; | ||
} | ||
catch ( final Exception e ) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public void setProjectName( final String value ) | ||
{ | ||
this.projectName = value; | ||
} | ||
|
||
@Override | ||
public void initialize( final BeanContext context ) | ||
{ | ||
this.indexService = context.getService( IndexService.class ); | ||
this.contentService = context.getService( ContentService.class ); | ||
this.exportService = context.getService( ExportService.class ); | ||
} | ||
|
||
private <T> T runAs( final Context context, final Callable<T> runnable ) | ||
{ | ||
return context.callWith( runnable ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
<node> | ||
<id>4e77783a-b96e-40bb-a49a-d7904a0097a8</id> | ||
<childOrder>modifiedtime DESC</childOrder> | ||
<nodeType>content</nodeType> | ||
<timestamp>2020-09-23T12:34:46.492Z</timestamp> | ||
<inheritPermissions>false</inheritPermissions> | ||
<permissions> | ||
<principal key="role:cms.cm.app"> | ||
<allow type="array"> | ||
<value>READ</value> | ||
</allow> | ||
<deny type="array"/> | ||
</principal> | ||
<principal key="role:system.admin"> | ||
<allow type="array"> | ||
<value>READ</value> | ||
<value>CREATE</value> | ||
<value>MODIFY</value> | ||
<value>DELETE</value> | ||
<value>PUBLISH</value> | ||
<value>READ_PERMISSIONS</value> | ||
<value>WRITE_PERMISSIONS</value> | ||
</allow> | ||
<deny type="array"/> | ||
</principal> | ||
<principal key="role:cms.admin"> | ||
<allow type="array"> | ||
<value>READ</value> | ||
<value>CREATE</value> | ||
<value>MODIFY</value> | ||
<value>DELETE</value> | ||
<value>PUBLISH</value> | ||
<value>READ_PERMISSIONS</value> | ||
<value>WRITE_PERMISSIONS</value> | ||
</allow> | ||
<deny type="array"/> | ||
</principal> | ||
</permissions> | ||
<data> | ||
<boolean name="valid">true</boolean> | ||
<string name="displayName">Headless Movie Database</string> | ||
<string name="type">portal:site</string> | ||
<string name="owner">user:system:su</string> | ||
<string name="language">en</string> | ||
<dateTime name="modifiedTime">2019-04-09T13:42:58.619Z</dateTime> | ||
<string name="modifier">user:system:anonymous</string> | ||
<string name="creator">user:system:su</string> | ||
<dateTime name="createdTime">2018-07-02T06:27:56.773Z</dateTime> | ||
<property-set name="publish"> | ||
<dateTime isNull="true" name="first"/> | ||
<dateTime isNull="true" name="from"/> | ||
<dateTime isNull="true" name="to"/> | ||
</property-set> | ||
<property-set name="data"> | ||
<string isNull="true" name="description"/> | ||
<property-set name="siteConfig"> | ||
<string name="applicationKey">com.enonic.app.hmdb</string> | ||
<property-set name="config"/> | ||
</property-set> | ||
</property-set> | ||
</data> | ||
<indexConfigs> | ||
<defaultConfig> | ||
<decideByType>true</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</defaultConfig> | ||
<pathIndexConfigs> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>data.siteConfig.applicationkey</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>true</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>x.*</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>true</nGram> | ||
<fulltext>true</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>attachment.text</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>type</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>false</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>site</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>owner</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>modifier</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>modifiedTime</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>true</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>language</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>true</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>data</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>creator</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>createdTime</path> | ||
</pathIndexConfig> | ||
<pathIndexConfig> | ||
<indexConfig> | ||
<decideByType>false</decideByType> | ||
<enabled>true</enabled> | ||
<nGram>false</nGram> | ||
<fulltext>false</fulltext> | ||
<includeInAllText>false</includeInAllText> | ||
</indexConfig> | ||
<path>attachment</path> | ||
</pathIndexConfig> | ||
</pathIndexConfigs> | ||
<allTextIndexConfig> | ||
<languages> | ||
<language>en</language> | ||
</languages> | ||
</allTextIndexConfig> | ||
</indexConfigs> | ||
</node> |
Oops, something went wrong.