Search in sources :

Example 1 with EntityInformation

use of net.nemerosa.ontrack.extension.api.model.EntityInformation in project ontrack by nemerosa.

the class ProjectEntityExtensionController method getInformation.

/**
 * Gets the list of information extensions for an entity
 */
@RequestMapping(value = "information/{entityType}/{id}", method = RequestMethod.GET)
public Resources<EntityInformation> getInformation(@PathVariable ProjectEntityType entityType, @PathVariable ID id) {
    // Gets the entity
    ProjectEntity entity = getEntity(entityType, id);
    // List of informations to return
    List<EntityInformation> informations = extensionManager.getExtensions(EntityInformationExtension.class).stream().map(x -> x.getInformation(entity)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    // OK
    return Resources.of(informations, uri(MvcUriComponentsBuilder.on(getClass()).getInformation(entityType, id)));
}
Also used : EntityInformationExtension(net.nemerosa.ontrack.extension.api.EntityInformationExtension) PathVariable(org.springframework.web.bind.annotation.PathVariable) EntityInformation(net.nemerosa.ontrack.extension.api.model.EntityInformation) StructureService(net.nemerosa.ontrack.model.structure.StructureService) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Action(net.nemerosa.ontrack.model.support.Action) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) ProjectEntityType(net.nemerosa.ontrack.model.structure.ProjectEntityType) ProjectEntityActionExtension(net.nemerosa.ontrack.extension.api.ProjectEntityActionExtension) List(java.util.List) Resources(net.nemerosa.ontrack.ui.resource.Resources) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) EntityInformationExtension(net.nemerosa.ontrack.extension.api.EntityInformationExtension) ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity) Optional(java.util.Optional) ExtensionManager(net.nemerosa.ontrack.extension.api.ExtensionManager) ID(net.nemerosa.ontrack.model.structure.ID) Optional(java.util.Optional) ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity) EntityInformation(net.nemerosa.ontrack.extension.api.model.EntityInformation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EntityInformation

use of net.nemerosa.ontrack.extension.api.model.EntityInformation in project ontrack by nemerosa.

the class BuildSVNInformationExtension method getInformation.

@Override
public Optional<EntityInformation> getInformation(ProjectEntity entity) {
    if (entity instanceof Build) {
        Build build = (Build) entity;
        // Gets the branch SVN information
        Property<SVNBranchConfigurationProperty> branchConfigurationProperty = propertyService.getProperty(build.getBranch(), SVNBranchConfigurationPropertyType.class);
        Property<SVNProjectConfigurationProperty> projectConfigurationProperty = propertyService.getProperty(build.getBranch().getProject(), SVNProjectConfigurationPropertyType.class);
        if (branchConfigurationProperty.isEmpty() || projectConfigurationProperty.isEmpty()) {
            return Optional.empty();
        } else {
            // Loads the repository
            SVNRepository repository = svnService.getRepository(projectConfigurationProperty.getValue().getConfiguration().getName());
            // Gets the build history
            try (Transaction ignored = transactionService.start()) {
                return Optional.of(new EntityInformation(this, svnChangeLogService.getBuildSVNHistory(repository, build)));
            }
        }
    } else {
        return Optional.empty();
    }
}
Also used : Transaction(net.nemerosa.ontrack.tx.Transaction) SVNProjectConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty) Build(net.nemerosa.ontrack.model.structure.Build) SVNBranchConfigurationProperty(net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty) EntityInformation(net.nemerosa.ontrack.extension.api.model.EntityInformation) SVNRepository(net.nemerosa.ontrack.extension.svn.db.SVNRepository)

Aggregations

EntityInformation (net.nemerosa.ontrack.extension.api.model.EntityInformation)2 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 EntityInformationExtension (net.nemerosa.ontrack.extension.api.EntityInformationExtension)1 ExtensionManager (net.nemerosa.ontrack.extension.api.ExtensionManager)1 ProjectEntityActionExtension (net.nemerosa.ontrack.extension.api.ProjectEntityActionExtension)1 SVNRepository (net.nemerosa.ontrack.extension.svn.db.SVNRepository)1 SVNBranchConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNBranchConfigurationProperty)1 SVNProjectConfigurationProperty (net.nemerosa.ontrack.extension.svn.property.SVNProjectConfigurationProperty)1 Build (net.nemerosa.ontrack.model.structure.Build)1 ID (net.nemerosa.ontrack.model.structure.ID)1 ProjectEntity (net.nemerosa.ontrack.model.structure.ProjectEntity)1 ProjectEntityType (net.nemerosa.ontrack.model.structure.ProjectEntityType)1 StructureService (net.nemerosa.ontrack.model.structure.StructureService)1 Action (net.nemerosa.ontrack.model.support.Action)1 Transaction (net.nemerosa.ontrack.tx.Transaction)1 Resources (net.nemerosa.ontrack.ui.resource.Resources)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1