apetrov
I'm new here

Content Transport Feature per API erstellen

Jump to solution

Hallo Community, ich versuche per API im FS ein ContentTransport-Feature zu erstellen, mein code dazu sieht wie

folgt aus...

public static void main(String[] args) {

        project = connection.getProjectByName("Mithras Energy");

        TemplateStoreRoot templateStore = project.getUserService().getTemplateStore();

        try {

            InputStream featureStream = createFeature(templateStore.getStoreElement(2485));

            File f = new File("feature.zip");

            OutputStream out = new FileOutputStream(f);

            byte buf[] = new byte[1024];

            int len;

            while ((len = featureStream.read(buf)) > 0) {

                out.write(buf, 0, len);

                out.close();

                featureStream.close();

            }

        } catch (IOException ex) {

            ConnectionManager.closeInstance();

            System.out.println(ex.toString());

        } catch (Exception ex) {

            ConnectionManager.closeInstance();

            System.out.println(ex.toString());

        }

    }

    public static InputStream createFeature(IDProvider idProvider) throws IOException {

        SpecialistsBroker broker = connection.getBroker().requireSpecialist(BrokerAgent.TYPE).getBrokerByProjectName(project.getName());

        FeatureAgent agent = broker.requireSpecialist(FeatureAgent.TYPE);

        Revision revision = project.getRevision(20281);

        FeatureDescriptor featureDescriptor = agent.createFeature(idProvider.getUid(), revision, false);

        FeatureModel featureModel = agent.createFeatureModel(featureDescriptor);

        featureModel.add(idProvider);//returns true

        agent.saveFeature(featureModel);

        ServerActionHandle<? extends FeatureProgress, Boolean> featureProgress = agent.createFeatureTransportFile(featureDescriptor);

        FeatureProgress progress = featureProgress.getProgress(true);

        return agent.downloadFeatureFile(progress.getFeatureFile());

    }

Als Ergebnis bekomme ich zwar eine Feature-Datei, die aber nur die Dateien info.txt, feature.xml und entries.xml beinhaltet, also sozusagen leer ist. Beim Debuggen habe ich festgestellt, dass nach

...

featureModel.add(idProvider);//returns true

agent.saveFeature(featureModel);

...

der FeatureDescriptor immernoch keine _elementIdentifiers besitzt, also habe ich den Code dahingehend abgewandelt...

        ...

        featureModel.add(idProvider);

        agent.saveFeature(featureModel);

        List<FeatureDescriptor> featureDescriptors = agent.getFeatureDescriptors();

        for (FeatureDescriptor fd : featureDescriptors){

            if(fd.getFeatureName().equals(idProvider.getUid())){

                featureDescriptor = fd;

            }

        }

        ServerActionHandle<? extends FeatureProgress, Boolean> featureProgress = agent.createFeatureTransportFile(featureDescriptor);

        FeatureProgress progress = featureProgress.getProgress(true);

        return agent.downloadFeatureFile(progress.getFeatureFile());

        ...

_elementIdentifiers waren ab da nicht mehr leer, aber die generierte Datei war unvollständig und ließ sich nicht mehr öffnen.

0 Kudos
10 Replies

Wird man dann irgendwann zumindest die alten, nicht mehr benötigten Features wieder löschen können?

0 Kudos