Skip to content

Commit

Permalink
remove feature tags
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Jul 14, 2022
1 parent f467c62 commit 2e7d113
Show file tree
Hide file tree
Showing 29 changed files with 52 additions and 90 deletions.
39 changes: 39 additions & 0 deletions api/apps/api/src/migrations/api/1657544835000-RemoveFeatureTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class RemoveFeatureTags1657544835000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE features
DROP COLUMN tag;
`);

await queryRunner.query(`
DROP TYPE features_tags;
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE "features_tags" AS ENUM (
'bioregional',
'species'
);
`);

/**
* As we cannot know whether existing features are of bioregional or
* species kind, we set them all as "bioregional" arbitrarily. This should
* not really apply in practice, of course.
*/
await queryRunner.query(`
ALTER TABLE features
ADD COLUMN tag features_tags;
UPDATE features
SET tag = 'bioregional';
ALTER TABLE features
ALTER COLUMN tag SET NOT NULL;
`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export const geoFeatureResource: BaseServiceResource = {
moduleControllerPrefix: 'geo-features',
};

export enum FeatureTags {
bioregional = 'bioregional',
species = 'species',
}

export interface GeoFeatureCategory {
key: string;
distinctValues: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
PrimaryColumn,
} from 'typeorm';
import { BaseServiceResource } from '@marxan-api/types/resource.interface';
import { FeatureTag } from '@marxan/features/domain';
import { JobStatus } from '../scenarios/scenario.api.entity';
import { Project } from '../projects/project.api.entity';
import { User } from '../users/user.api.entity';
Expand Down Expand Up @@ -63,10 +62,6 @@ export class GeoFeature extends BaseEntity {
@Column('uuid')
intersection?: string[];

@ApiProperty()
@Column('varchar')
tag!: FeatureTag;

@Column('varchar', { name: 'creation_status' })
creationStatus?: JobStatus;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { AppInfoDTO } from '@marxan-api/dto/info.dto';
import { BBox } from 'geojson';
import { FeatureTags } from './geo-feature-set.api.entity';

export interface GeoFeaturesRequestInfo extends AppInfoDTO {
params?: {
featureClassAndAliasFilter?: string;
projectId?: string;
bbox?: BBox;
ids?: string[];
featureTag?: FeatureTags | FeatureTags[];
};
}
10 changes: 0 additions & 10 deletions api/apps/api/src/modules/geo-features/geo-features.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const geoFeatureFilterKeyNames = [
'description',
'source',
'propertyName',
'tag',
'projectId',
] as const;
type GeoFeatureFilterKeys = keyof Pick<
Expand Down Expand Up @@ -87,7 +86,6 @@ export class GeoFeaturesService extends AppBaseService<
'source',
'propertyName',
'intersection',
'tag',
'properties',
'isCustom',
],
Expand Down Expand Up @@ -160,7 +158,6 @@ export class GeoFeaturesService extends AppBaseService<
* at some point, per project]
* 2 move api.features into geo.features_data ...
* 3 which also fixes issues with:
* * searching via tag
* * searching via name
* * pagination
* * searching within one query (table) and single db
Expand Down Expand Up @@ -227,12 +224,6 @@ export class GeoFeaturesService extends AppBaseService<
);
}

if (info.params?.featureTag) {
queryFilteredByPublicOrProjectSpecificFeatures.andWhere(
`${this.alias}.tag = :tag`,
{ tag: info.params.featureTag },
);
}
return queryFilteredByPublicOrProjectSpecificFeatures;
}

Expand Down Expand Up @@ -363,7 +354,6 @@ export class GeoFeaturesService extends AppBaseService<
id: v4(),
featureClassName: data.name,
description: data.description,
tag: data.type,
projectId,
creationStatus: JobStatus.done,
}),
Expand Down
5 changes: 0 additions & 5 deletions api/apps/api/src/modules/projects/dto/upload-shapefile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FeatureTag } from '@marxan/features';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsString } from 'class-validator';

Expand All @@ -7,10 +6,6 @@ export class UploadShapefileDTO {
@IsString()
name!: string;

@ApiProperty()
@IsEnum(Object.values(FeatureTag))
type!: FeatureTag;

@ApiPropertyOptional()
@IsOptional()
@IsString()
Expand Down
3 changes: 0 additions & 3 deletions api/apps/api/src/modules/projects/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import { ShapefileService } from '@marxan/shapefile-converter';
import { isFeatureCollection } from '@marxan/utils';
import { asyncJobTag } from '@marxan-api/dto/async-job-tag';
import { inlineJobTag } from '@marxan-api/dto/inline-job-tag';
import { FeatureTags } from '@marxan-api/modules/geo-features/geo-feature-set.api.entity';
import { UpdateProjectBlmRangeDTO } from '@marxan-api/modules/projects/dto/update-project-blm-range.dto';
import { invalidRange } from '@marxan-api/modules/projects/blm';
import {
Expand Down Expand Up @@ -172,7 +171,6 @@ export class ProjectsController {
@Param('projectId', ParseUUIDPipe) projectId: string,
@Req() req: RequestWithAuthenticatedUser,
@Query('q') featureClassAndAliasFilter?: string,
@Query('tag') featureTag?: FeatureTags,
): Promise<GeoFeatureResult> {
const result = await this.projectsService.findAllGeoFeatures(
fetchSpecification,
Expand All @@ -181,7 +179,6 @@ export class ProjectsController {
params: {
projectId: projectId,
featureClassAndAliasFilter: featureClassAndAliasFilter,
featureTag,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ScenarioFeaturesData } from '@marxan/features';
import { FeatureTag } from '@marxan/features/domain';
import { GeoFeature } from '../../geo-features/geo-feature.api.entity';

const featureIdMet = `feature-uuid-1-criteria-met`;
Expand Down Expand Up @@ -56,13 +55,11 @@ export const getValidGeoFeature = (): GeoFeature[] => {
entity1.id = metaFeatureIdMet;
entity1.alias = 'feature-alias-1';
entity1.description = 'feature-desc-1';
entity1.tag = FeatureTag.Bioregional;

const entity2 = new GeoFeature();
entity2.id = metaFeatureIdFailed;
entity2.alias = 'feature-alias-2';
entity2.description = 'feature-desc-2';
entity2.tag = FeatureTag.Species;

return [entity1, entity2];
};
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export class ScenarioFeaturesGapDataService extends AppBaseService<
'coverageTarget',
'featureClassName',
'name',
'tag',
'description',
],
keyForAttribute: 'camelCase',
Expand All @@ -191,7 +190,6 @@ export class ScenarioFeaturesGapDataService extends AppBaseService<
return {
...base,
featureClassName: assign.featureClassName ?? undefined,
tag: assign.tag,
name: assign.alias ?? undefined, // `null`
description: assign.description ?? undefined,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export class ScenarioFeaturesOutputGapDataService extends AppBaseService<
'coverageTarget',
'featureClassName',
'name',
'tag',
'description',
],
keyForAttribute: 'camelCase',
Expand All @@ -217,7 +216,6 @@ export class ScenarioFeaturesOutputGapDataService extends AppBaseService<
return {
...base,
featureClassName: assign.featureClassName ?? undefined,
tag: assign.tag,
name: assign.alias ?? undefined, // `null`
description: assign.description ?? undefined,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ describe(`when looking for a scenario's features`, () => {
"name": "feature-alias-1",
"onTarget": true,
"scenarioId": "scenarioId",
"tag": "bioregional",
"target": 50,
"target2": 0,
"totalArea": 20000,
Expand All @@ -100,7 +99,6 @@ describe(`when looking for a scenario's features`, () => {
"name": "feature-alias-2",
"onTarget": false,
"scenarioId": "scenarioId",
"tag": "species",
"target": 50,
"target2": 0,
"totalArea": 10000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export class ScenarioFeaturesService extends AppBaseService<
attributes: [
'description',
'name',
'tag',
'onTarget',
'metArea',
'met',
Expand Down Expand Up @@ -112,7 +111,6 @@ export class ScenarioFeaturesService extends AppBaseService<
coverageTarget: +(base?.target ?? 0).toFixed(2),
coverageTargetArea: +((totalArea * (base?.target ?? 0)) / 100).toFixed(2),
totalArea: +totalArea.toFixed(2),
tag: assign.tag,
name: assign.alias ?? undefined, // `null`
description: assign.description ?? undefined,
};
Expand Down
12 changes: 10 additions & 2 deletions api/apps/api/test/fixtures/test-features.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@

INSERT INTO features
(feature_class_name, alias, description, property_name, intersection, tag, creation_status, created_by)
(feature_class_name, alias, description, property_name, intersection, creation_status, created_by)
VALUES
('demo_acinonyx_jubatus', 'Acinonyx_jubatus', null, ' name', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_bucorvus_leadbeateri', 'Bucorvus_leadbeateri', null, ' id', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_ceratotherium_simum', 'Ceratotherium_simum', null, ' name', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_civettictis_civetta', 'Civettictis_civetta', null, ' id', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_diceros_bicornis', 'Diceros_bicornis', null, ' name', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_equus_quagga', 'Equus_quagga', null, ' name', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_giraffa_camelopardalis', 'Giraffa_camelopardalis', null, ' name', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_kobus_leche', 'Kobus_leche', null, ' name', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com')), ('demo_panthera_pardus', 'Panthera_pardus', null, ' name', null, 'species', 'created', (SELECT id FROM users WHERE email = 'aa@example.com'));
('demo_acinonyx_jubatus', 'Acinonyx_jubatus', null, ' name', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_bucorvus_leadbeateri', 'Bucorvus_leadbeateri', null, ' id', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_ceratotherium_simum', 'Ceratotherium_simum', null, ' name', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_civettictis_civetta', 'Civettictis_civetta', null, ' id', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_diceros_bicornis', 'Diceros_bicornis', null, ' name', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_equus_quagga', 'Equus_quagga', null, ' name', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_giraffa_camelopardalis', 'Giraffa_camelopardalis', null, ' name', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_kobus_leche', 'Kobus_leche', null, ' name', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com')),
('demo_panthera_pardus', 'Panthera_pardus', null, ' name', null, 'created', (SELECT id FROM users WHERE email = 'aa@example.com'));
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe(`when user is logged in`, () => {
"met": 110.94,
"metArea": 49461858904.37,
"onTarget": true,
"tag": "species",
"totalArea": 44582822387.74,
},
Object {
Expand All @@ -56,7 +55,6 @@ describe(`when user is logged in`, () => {
"met": 0,
"metArea": 0,
"onTarget": false,
"tag": "species",
"totalArea": 2369906750.34,
},
Object {
Expand All @@ -65,7 +63,6 @@ describe(`when user is logged in`, () => {
"met": 0,
"metArea": 0,
"onTarget": false,
"tag": "species",
"totalArea": 7556941342.9,
},
Object {
Expand All @@ -74,7 +71,6 @@ describe(`when user is logged in`, () => {
"met": 237.02,
"metArea": 41436305173.17,
"onTarget": true,
"tag": "species",
"totalArea": 17482394162.77,
},
Object {
Expand All @@ -83,7 +79,6 @@ describe(`when user is logged in`, () => {
"met": 105.34,
"metArea": 49461858904.37,
"onTarget": true,
"tag": "species",
"totalArea": 46952729138.08,
},
Object {
Expand All @@ -92,7 +87,6 @@ describe(`when user is logged in`, () => {
"met": 163.6,
"metArea": 47131396118.24,
"onTarget": true,
"tag": "species",
"totalArea": 28809765713.5,
},
Object {
Expand All @@ -101,7 +95,6 @@ describe(`when user is logged in`, () => {
"met": 12.84,
"metArea": 2330463199.05,
"onTarget": false,
"tag": "species",
"totalArea": 18142963424.57,
},
]
Expand Down
3 changes: 0 additions & 3 deletions api/apps/api/test/upload-feature/upload-feature.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const getFixtures = async () => {
},
);
const customFeatureName = `User custom feature ${Date.now()}`;
const customFeatureTag = `bioregional`;
const customFeatureDesc = `User custom feature desc`;

const geoFeaturesApiRepo: Repository<GeoFeature> = app.get(
Expand Down Expand Up @@ -59,7 +58,6 @@ export const getFixtures = async () => {
.attach(`file`, __dirname + `/wetlands.zip`)
.field({
name: customFeatureName,
type: customFeatureTag,
description: customFeatureDesc,
}),
ThenGeoFeaturesAreCreated: async (result: request.Response) => {
Expand All @@ -79,7 +77,6 @@ export const getFixtures = async () => {
alias: null,
propertyName: null,
intersection: null,
tag: customFeatureTag,
creationStatus: `done`,
projectId,
isCustom: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ProjectCustomFeature,
ProjectCustomFeaturesContent,
} from '@marxan/cloning/infrastructure/clone-piece-data/project-custom-features';
import { FeatureTag } from '@marxan/features';
import { CloningFilesRepository } from '@marxan/cloning-files-repository';
import { GeometrySource } from '@marxan/geofeatures';
import { Injectable, Logger } from '@nestjs/common';
Expand All @@ -28,7 +27,6 @@ type ProjectCustomFeaturesSelectResult = {
description: string;
property_name: string;
intersection: string[];
tag: FeatureTag;
creation_status: CreationStatus;
list_property_keys: string[];
is_legacy: boolean;
Expand Down Expand Up @@ -73,7 +71,6 @@ export class ProjectCustomFeaturesPieceExporter
'description',
'property_name',
'intersection',
'tag',
'creation_status',
'list_property_keys',
'is_legacy',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ProjectsPuEntity,
} from '@marxan-jobs/planning-unit-geometry';
import { JobStatus } from '@marxan/cloning/infrastructure/clone-piece-data/project-custom-features';
import { FeatureTag } from '@marxan/features';
import { GeoFeatureGeometry, GeometrySource } from '@marxan/geofeatures';
import {
LegacyProjectImportFileSnapshot,
Expand Down Expand Up @@ -281,7 +280,6 @@ export class FeaturesLegacyProjectPieceImporter
project_id: projectId,
id: featureId,
feature_class_name: feature.name,
tag: FeatureTag.Species,
creation_status: JobStatus.created,
created_by: input.ownerId,
is_legacy: true,
Expand Down
Loading

0 comments on commit 2e7d113

Please sign in to comment.