-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(entities,resources): Decouple parsing from entities hook int…
…o separate serializer class * create CamelResourceSerializer interface and YamlCamelResourceSerializer implementantion * create CamelResourceFactory and CamelKResourceFactory to creating new resources * move parsing out of the entities hook
- Loading branch information
Showing
15 changed files
with
210 additions
and
144 deletions.
There are no files selected for viewing
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
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,33 @@ | ||
import { SourceSchemaType } from './source-schema-type'; | ||
import { CamelResource } from './camel-resource'; | ||
import { IntegrationResource } from './integration-resource'; | ||
import { KameletResource } from './kamelet-resource'; | ||
import { KameletBindingResource } from './kamelet-binding-resource'; | ||
import { PipeResource } from './pipe-resource'; | ||
import { IKameletDefinition } from '../kamelets-catalog'; | ||
import { | ||
Integration as IntegrationType, | ||
KameletBinding as KameletBindingType, | ||
Pipe as PipeType, | ||
} from '@kaoto/camel-catalog/types'; | ||
|
||
export class CamelKResourceFactory { | ||
static getCamelKResource(json?: unknown, type?: SourceSchemaType): CamelResource | undefined { | ||
const jsonRecord = json as Record<string, unknown>; | ||
if ((jsonRecord && typeof json === 'object' && 'kind' in jsonRecord) || type) { | ||
switch (jsonRecord['kind'] || type) { | ||
case SourceSchemaType.Integration: | ||
return new IntegrationResource(json as IntegrationType); | ||
case SourceSchemaType.Kamelet: | ||
return new KameletResource(json as IKameletDefinition); | ||
case SourceSchemaType.KameletBinding: | ||
return new KameletBindingResource(json as KameletBindingType); | ||
case SourceSchemaType.Pipe: | ||
return new PipeResource(json as PipeType); | ||
default: | ||
return undefined; | ||
} | ||
} | ||
return undefined; | ||
} | ||
} |
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
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,27 @@ | ||
import { SourceSchemaType } from './source-schema-type'; | ||
import { CamelResource } from './camel-resource'; | ||
import { XmlCamelResourceSerializer, YamlCamelResourceSerializer } from '../../serializers'; | ||
import { CamelRouteResource } from './camel-route-resource'; | ||
import { CamelKResourceFactory } from './camel-k-resource-factory'; | ||
|
||
export class CamelResourceFactory { | ||
/** | ||
* Creates a CamelResource based on the given {@link type} and {@link source}. If | ||
* both are not specified, a default empty {@link CamelRouteResource} is created. | ||
* If only {@link type} is specified, an empty {@link CamelResource} of the given | ||
* {@link type} is created. | ||
* @param type | ||
* @param source | ||
*/ | ||
static createCamelResource(source?: string, type?: SourceSchemaType): CamelResource { | ||
if (XmlCamelResourceSerializer.isApplicable(source)) { | ||
return new CamelRouteResource(source, new XmlCamelResourceSerializer()); | ||
} | ||
|
||
const serializer = new YamlCamelResourceSerializer(); | ||
const resource = CamelKResourceFactory.getCamelKResource(serializer.parse(source ?? ''), type); | ||
|
||
if (resource) return resource; | ||
return new CamelRouteResource(source, serializer); | ||
} | ||
} |
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
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
Oops, something went wrong.