Skip to content

Commit

Permalink
Revert "De cf schema-tree & recursive delete"
Browse files Browse the repository at this point in the history
This reverts commit 2c5647e.
  • Loading branch information
richard-cox committed Sep 20, 2019
1 parent 922fc23 commit f7044d7
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 152 deletions.
73 changes: 1 addition & 72 deletions src/frontend/packages/cloud-foundry/src/cf-entity-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ import { BaseEndpointAuth } from '../../core/src/features/endpoints/endpoint-aut
import { JetstreamResponse } from '../../store/src/entity-request-pipeline/entity-request-pipeline.types';
import { endpointDisconnectRemoveEntitiesReducer } from '../../store/src/reducers/endpoint-disconnect-application.reducer';
import { APIResource } from '../../store/src/types/api.types';
import { APISuccessOrFailedAction, ICFAction } from '../../store/src/types/request.types';
import { IFavoriteMetadata } from '../../store/src/types/user-favorites.types';
import { CF_ENDPOINT_TYPE } from '../cf-types';
import { DELETE_SUCCESS, DeleteApplication } from './actions/application.actions';
import {
appEnvVarsEntityType,
appEventEntityType,
Expand Down Expand Up @@ -354,17 +352,6 @@ function generateCFUserProvidedServiceInstanceEntity(endpointDefinition: Stratos
label: 'User Provided Service Instance',
labelPlural: 'User Provided Service Instances',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
servicePlanEntityType,
// Service bindings
applicationEntityType,
serviceInstancesEntityType,
serviceEntityType,
organizationEntityType,
spaceEntityType
],
}
};
return new StratosCatalogueEntity<IFavoriteMetadata, APIResource<IUserProvidedServiceInstance>>(
definition,
Expand Down Expand Up @@ -495,14 +482,7 @@ function generateCFServiceBindingEntity(endpointDefinition: StratosEndpointExten
},
label: 'Service Binding',
labelPlural: 'Service Bindings',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
applicationEntityType,
serviceInstancesEntityType,
serviceEntityType
],
}
endpoint: endpointDefinition
};
return new StratosCatalogueEntity<IFavoriteMetadata, APIResource<IServiceBinding>>(
definition,
Expand Down Expand Up @@ -582,15 +562,6 @@ function generateCFServiceInstanceEntity(endpointDefinition: StratosEndpointExte
label: 'Marketplace Service Instance',
labelPlural: 'Marketplace Service Instances',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
servicePlanEntityType,
// Service bindings
applicationEntityType,
serviceInstancesEntityType,
serviceEntityType
],
}
};
return new StratosCatalogueEntity<IFavoriteMetadata, APIResource<IServiceInstance>>(
definition,
Expand All @@ -617,12 +588,6 @@ function generateCFUserEntity(endpointDefinition: StratosEndpointExtensionDefini
label: 'User',
labelPlural: 'Users',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
organizationEntityType,
spaceEntityType
],
}
};
return new StratosCatalogueEntity<IFavoriteMetadata, APIResource<CfUser>>(
definition,
Expand Down Expand Up @@ -773,13 +738,6 @@ function generateRouteEntity(endpointDefinition: StratosEndpointExtensionDefinit
label: 'Application Route',
labelPlural: 'Application Routes',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
domainEntityType,
applicationEntityType,
spaceEntityType
],
}

};
return new StratosCatalogueEntity<IBasicCFMetaData, APIResource<IRoute>>(
Expand Down Expand Up @@ -884,18 +842,6 @@ function generateCfApplicationEntity(endpointDefinition: StratosEndpointExtensio
label: 'Application',
labelPlural: 'Applications',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
stackEntityType,
spaceEntityType,
routeEntityType,
serviceBindingEntityType,
serviceInstancesEntityType
],
deleteSuccessApiActionGenerators: (guid: string, endpointGuid: string) => {
return new APISuccessOrFailedAction(DELETE_SUCCESS, new DeleteApplication(guid, endpointGuid) as ICFAction);
}
}
};

return new StratosCatalogueEntity<IAppFavMetadata, APIResource<IApp>>(
Expand Down Expand Up @@ -929,16 +875,6 @@ function generateCfSpaceEntity(endpointDefinition: StratosEndpointExtensionDefin
label: 'Space',
labelPlural: 'Spaces',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
domainEntityType,
// Service instance related
serviceEntityType,
servicePlanEntityType,
// App Related
stackEntityType
],
}
};
return new StratosCatalogueEntity<ISpaceFavMetadata, APIResource<ISpace>>(
spaceDefinition,
Expand Down Expand Up @@ -971,13 +907,6 @@ function generateCfOrgEntity(endpointDefinition: StratosEndpointExtensionDefinit
label: 'Organization',
labelPlural: 'Organizations',
endpoint: endpointDefinition,
recursiveDelete: {
excludes: [
domainEntityType,
quotaDefinitionEntityType,
privateDomainsEntityType
],
}
};
return new StratosCatalogueEntity<IOrgFavMetadata, APIResource<IOrganization>>(
orgDefinition,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action, ActionReducer, Store } from '@ngrx/store';
import { ActionReducer, Store } from '@ngrx/store';
import { normalize } from 'normalizr';

import { AppState, IRequestEntityTypeState } from '../../../../store/src/app-state';
Expand Down Expand Up @@ -30,11 +30,6 @@ import {
StratosEndpointExtensionDefinition,
} from './entity-catalogue.types';

export interface RecursiveDeleteConfig {
excludes?: string[];
deleteSuccessApiActionGenerators?: (guid: string, endpointGuid: string) => Action;
}

export interface EntityCatalogueBuilders<
T extends IEntityMetadata = IEntityMetadata,
Y = any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { EntitySchema } from '../../../../store/src/helpers/entity-schema';
import { StratosStatus } from '../../shared/shared.types';
import { EndpointAuthTypeConfig } from '../extension/extension-types';
import { Omit } from '../utils.service';
import { RecursiveDeleteConfig } from './entity-catalogue-entity';

export interface EntityCatalogueEntityConfig {
entityType: string;
Expand Down Expand Up @@ -66,7 +65,6 @@ export interface IStratosBaseEntityDefinition<T = EntitySchema | EntityCatalogue
readonly parentType?: string;
readonly subTypes?: Omit<IStratosBaseEntityDefinition, 'schema' | 'subTypes'>[];
readonly paginationConfig?: PaginationPageIteratorConfig;
readonly recursiveDelete?: RecursiveDeleteConfig;
}


Expand Down Expand Up @@ -119,7 +117,6 @@ export interface IStratosEntityDefinition<
// This will override any globalPreRequest found in the endpoint.
readonly preRequest?: PreApiRequest;
readonly prePaginationRequest?: PrePaginationApiRequest;
readonly recursiveDelete?: RecursiveDeleteConfig;
}

export interface IStratosEntityActions extends Partial<IStratosEntityWithIcons> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { Actions, Effect, ofType } from '@ngrx/effects';
import { Action, Store } from '@ngrx/store';
import { map, mergeMap, withLatestFrom } from 'rxjs/operators';

import { StratosBaseCatalogueEntity } from '../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import { DELETE_SUCCESS, DeleteApplication } from '../../../cloud-foundry/src/actions/application.actions';
import { ClearPaginationOfType } from '../actions/pagination.actions';
import { GeneralEntityAppState, GeneralRequestDataState } from '../app-state';
import { EntitySchema } from '../helpers/entity-schema';
import { EntitySchemaTreeBuilder, IFlatTree } from '../helpers/schema-tree-traverse';
import { getAPIRequestDataState } from '../selectors/api.selectors';
import { APISuccessOrFailedAction, ICFAction } from '../types/request.types';


export const RECURSIVE_ENTITY_DELETE = '[Entity] Recursive entity delete';
Expand All @@ -20,38 +22,22 @@ export const RECURSIVE_ENTITY_SET_DELETED = '[Entity] Recursive entity set delet

export interface IRecursiveDelete {
guid: string;
// Keep this in case it's not the default associated with the entity config
schemaKey: string;
entityConfig: StratosBaseCatalogueEntity;
schema: EntitySchema;
}

export class RecursiveDelete implements Action, IRecursiveDelete {
public type = RECURSIVE_ENTITY_DELETE;
constructor(
public guid: string,
public schemaKey: string,
public entityConfig: StratosBaseCatalogueEntity
) { }
constructor(public guid: string, public schema: EntitySchema) { }
}

export class RecursiveDeleteComplete implements Action, IRecursiveDelete {
public type = RECURSIVE_ENTITY_DELETE_COMPLETE;
constructor(
public guid: string,
public endpointGuid: string,
public schemaKey: string,
public entityConfig: StratosBaseCatalogueEntity
) { }
constructor(public guid: string, public endpointGuid: string, public schema: EntitySchema) { }
}

export class RecursiveDeleteFailed implements Action, IRecursiveDelete {
public type = RECURSIVE_ENTITY_DELETE_FAILED;
constructor(
public guid: string,
public endpointGuid: string,
public schemaKey: string,
public entityConfig: StratosBaseCatalogueEntity
) { }
constructor(public guid: string, public endpointGuid: string, public schema: EntitySchema) { }
}

export class SetTreeDeleting implements Action {
Expand All @@ -77,6 +63,12 @@ export class RecursiveDeleteEffect {
private store: Store<GeneralEntityAppState>
) { }

private deleteSuccessApiActionGenerators = {
application: (guid: string, endpointGuid: string) => {
return new APISuccessOrFailedAction(DELETE_SUCCESS, new DeleteApplication(guid, endpointGuid) as ICFAction);
}
};

@Effect()
delete$ = this.actions$.pipe(
ofType<RecursiveDelete>(RECURSIVE_ENTITY_DELETE),
Expand All @@ -95,12 +87,10 @@ export class RecursiveDeleteEffect {
const tree = this.getTree(action, state);
const actions = new Array<Action>().concat(...Object.keys(tree).map<Action[]>(key => {
const keyActions = [];
const deleteSuccessApiActionGenerators = action.entityConfig.definition.recursiveDelete ?
(action.entityConfig.definition.recursiveDelete.deleteSuccessApiActionGenerators || null) : null;
if (deleteSuccessApiActionGenerators) {
keyActions.push(deleteSuccessApiActionGenerators[key](action.guid, action.endpointGuid));
if (this.deleteSuccessApiActionGenerators[key]) {
keyActions.push(this.deleteSuccessApiActionGenerators[key](action.guid, action.endpointGuid));
}
keyActions.push(new ClearPaginationOfType(action.entityConfig.getSchema(action.schemaKey)));
keyActions.push(new ClearPaginationOfType(action.schema));
return keyActions;
}));
actions.unshift(new SetTreeDeleted(action.guid, tree));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export function failedEntityHandler(
new RecursiveDeleteFailed(
action.guid,
action.endpointGuid,
action.schemaKey,
catalogueEntity
catalogueEntity.getSchema(action.schemaKey)
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EntityRequestAction } from '../../types/request.types';
import { StratosBaseCatalogueEntity } from '../../../../core/src/core/entity-catalogue/entity-catalogue-entity';
import { SendEventAction } from '../../actions/internal-events.actions';
import { RecursiveDeleteFailed } from '../../effects/recursive-entity-delete.effect';
import { endpointSchemaKey } from '../../helpers/entity-factory';
import { ApiRequestTypes, getFailApiRequestActions } from '../../reducers/api-request-reducer/request-helpers';
import { InternalEventSeverity } from '../../types/internal-events.types';
import { EntityRequestAction } from '../../types/request.types';
import { getFailApiRequestActions, ApiRequestTypes } from '../../reducers/api-request-reducer/request-helpers';
import { RecursiveDeleteFailed } from '../../effects/recursive-entity-delete.effect';
import { ActionDispatcher } from '../entity-request-pipeline.types';
import { PipelineHttpClient } from '../pipline-http-client.service';

Expand Down Expand Up @@ -42,8 +42,7 @@ export function jetstreamErrorHandler(
actionDispatcher(new RecursiveDeleteFailed(
action.guid,
action.endpointGuid,
action.schemaKey,
catalogueEntity
catalogueEntity.getSchema(action.schemaKey),
));
}
return errorActions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export function successEntityHandler(
new RecursiveDeleteComplete(
action.guid,
action.endpointGuid,
action.schemaKey,
catalogueEntity
catalogueEntity.getSchema(action.schemaKey)
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { entityCatalogue } from '../../../core/src/core/entity-catalogue/entity-
import { AppState, InternalAppState } from '../app-state';
import { RecursiveDelete } from '../effects/recursive-entity-delete.effect';
import { ApiRequestTypes, getRequestTypeFromMethod } from '../reducers/api-request-reducer/request-helpers';
import { PaginatedAction } from '../types/pagination.types';
import { EntityRequestAction } from '../types/request.types';
import { failedEntityHandler } from './entity-request-base-handlers/fail-entity-request.handler';
import { patchActionWithForcedConfig } from './entity-request-base-handlers/forced-action-type.helpers';
import { jetstreamErrorHandler } from './entity-request-base-handlers/jetstream-error.handler';
import { startEntityHandler } from './entity-request-base-handlers/start-entity-request.handler';
import { successEntityHandler } from './entity-request-base-handlers/success-entity-request.handler';
import { EntityRequestPipeline, PreApiRequest, SuccessfulApiResponseDataMapper } from './entity-request-pipeline.types';
import { PipelineHttpClient } from './pipline-http-client.service';
import { patchActionWithForcedConfig } from './entity-request-base-handlers/forced-action-type.helpers';
import { PaginatedAction } from '../types/pagination.types';

export interface PipelineFactoryConfig<T extends AppState = InternalAppState> {
store: Store<AppState>;
Expand Down Expand Up @@ -51,7 +51,7 @@ export const apiRequestPipelineFactory = (

if (recursivelyDelete) {
store.dispatch(
new RecursiveDelete(action.guid, action.schemaKey, catalogueEntity),
new RecursiveDelete(action.guid, catalogueEntity.getSchema(patchedAction.schemaKey)),
);
}

Expand Down
Loading

0 comments on commit f7044d7

Please sign in to comment.